【发布时间】:2016-08-10 23:25:43
【问题描述】:
我正在尝试计算一些指标,一旦 myclass 中的所有线程都完成,一旦我达到超时场景,线程的工作就完成了,我可以为每个线程命中。现在在 Group 类的 main() 方法中,我如何等待所有 myclass 线程完成?
我不想使用任何 sleep() 场景
Group Class
class myGroup {
public void run(int numThreads) {
executor = Executors.newFixedThreadPool(numThreads);
executor.submit(new myclass(threadNumber));
}
public static void main(String[] args) {
run(noOfthreads);
// Collect metrics once all the myclass threads are done.
}
}
我的班级
class myclass implements Runnable {
try{
}
catch(SomeTimeoutException cte){
// Job Done for thread
}
}
【问题讨论】:
-
你可能想看看
java.util.concurrent.CountDownLatch
标签: java multithreading threadpool executorservice