g****j 发帖数: 24 | 1 我通过swingworker同时启动了N个进程,执行不同的任务,我希望他们都结束以后
才继续执行下面的further(),可是further()也立即执行了。请问如何解决,多谢。
for(int i=0;i
SwingWorker worker = new SwingWorker() {
public Object construct() {
...
return null;
}
public void finished() {
...
}
};
worker.start();
}
...
further(); |
g*****g 发帖数: 34805 | 2 simplest way, keep an array of boolean, mark a boolean when a thread
is done. The main thread use a
while(boolean array is not completely set){
sleep
}
Or you can use notify to achieve better performance.
【在 g****j 的大作中提到】 : 我通过swingworker同时启动了N个进程,执行不同的任务,我希望他们都结束以后 : 才继续执行下面的further(),可是further()也立即执行了。请问如何解决,多谢。 : for(int i=0;i: SwingWorker worker = new SwingWorker() { : public Object construct() { : ... : return null; : } : public void finished() { : ...
|
g****j 发帖数: 24 | 3 嗯,好方法,多谢了。
【在 g*****g 的大作中提到】 : simplest way, keep an array of boolean, mark a boolean when a thread : is done. The main thread use a : while(boolean array is not completely set){ : sleep : } : Or you can use notify to achieve better performance.
|
c*****t 发帖数: 1879 | 4 CyclicBarrier of Java 1.5 can also be used.
【在 g****j 的大作中提到】 : 我通过swingworker同时启动了N个进程,执行不同的任务,我希望他们都结束以后 : 才继续执行下面的further(),可是further()也立即执行了。请问如何解决,多谢。 : for(int i=0;i: SwingWorker worker = new SwingWorker() { : public Object construct() { : ... : return null; : } : public void finished() { : ...
|
s******e 发帖数: 493 | 5 if you go for array of booleans, one thing you should consider is infinite
loop. This is always a concern with sleeping and polling.
cyclicbarrier should handle it more elegently. |