在B类中,我如何知道线程的工作是否完成?在属性之后,有一些工作正在运行。在B类中,我需要知道工作是否完成。
public class A implements InitializingBean{
public void method1(){
...
}
@Override
public void afterPropertiesSet() throws Exception {
System.out.print("test after properties set");
// send threads to executorService
ExecutorService executorService = Executors
.newFixedThreadPool(4);
for (int i = 0; i < 4; i++) {
Worker worker = new Worker();
executorService.submit(worker);
}
}
}
public class Worker implements Callable<Void>{
@Override
public void call(){
...
}
}
public class B{
public void methodB(){
A a = new A();
a.method1();
///Here How can i know the job of the workers are finished?
}
}
Service
所做的。你可以在想要监听完成的类中实现此接口,当线程完成工作时,它将调用该方法。 - Ryan J