|
这个主题共有 8 回复 / 1 页 [
]
|
|
|
|
|
|
请教一个多线程的问题
|
发表: 2006年04月19日 17:26
|
回复
|
|
public class VerifyQueryThread implements Runnable{ public void run(){ ... } }
public static void startMutiThread(){ VerifyQueryThread target = new VerifyQueryThread(); for(int j = 0; j < 40;j++){ (new Thread(target)).start(); } writeLog(); }
我希望writeLog()方法在那40个新开的线程都运行完毕后再执行 应该怎么改写代码? 谢谢
|
|
|
|
|
|
Re: 请教一个多线程的问题
|
发表: 2006年04月20日 11:56
|
回复
|
|
>40个新开的线程都运行完毕后再执行 自己用一个字段记录来进行40个线程完成后的标志,不用试图通过顺序编程就以为实际运行也是这样,线程编程的特点是:你无法控制线程的先后运行次序。
|
|
|
|
|
|
Re: 虢桃桓龆嘞叱痰奈侍? size=
|
发表: 2006年04月24日 13:24
|
回复
|
|
Thread 有个join方法,不知道是否合适? join() Waits for this thread to die.
|
|
|
|
|
|
re:请教一个多线程的问题
|
发表: 2007年05月24日 18:18
|
回复
|
|
banq说的设置个标志,是一种方案 然后你可以为你的这个方法封装成一个线程,让这个对象wait().然后再notify() 唤醒并执行你的方法
|
|
|
|
|
|
java0000000
|
发表: 2007年06月10日 16:47
|
回复
|
|
import java.lang.*; class VerifyQueryThread implements Runnable { int i=40; public void run() { while(i>0) { System.out.println(i--); } }
public static void startMutiThread() { VerifyQueryThread target = new VerifyQueryThread(); for(int j = 0; j < 40;j++) {
new Thread(target).start();
} System.out.println("Test"); //writeLog(); } public static void main(String [] args) { VerifyQueryThread tt=new VerifyQueryThread(); tt.startMutiThread(); } }
|
|
|
|
|
|
re:请教一个多线程的问题
|
发表: 2007年06月19日 10:58
|
回复
|
|
|
用Runnable 接口实现,,,自已设置一个数当进程启动到指定的数是置否就OK了
|
|
|
|
|
|
回复:re:请教一个多线程的问题
|
发表: 2007年06月21日 14:28
|
回复
|
|
|
|
|
|
|
|
re:请教一个多线程的问题
|
发表: 2007年06月24日 18:54
|
回复
|
|
应该设一个锁定的静态变量自增的方法不知道你能否试一下 当变量到40后设定一个flag标志退出 这方法在线程执行的最后执行
|
|
|
|
|
|
re:请教一个多线程的问题
|
发表: 2007年07月04日 12:54
|
回复
|
|
|
Thread不是有自己判断线程是否处于活动状态的方法吗 ?
|
|
|
|