使用 boost :: thread 开了一个线程,如何判断该线程是否进行完毕? 且如何释放该进程所用的资源? 5
2个回答
展开全部
你可以使用Future来做这件事情:
ExecutorService executorService = Executors
.newFixedThreadPool(10);
List<Future<Void>> futureList=new ArrayList<Future<Void>>();
for (int i = 0; i < partNumber - 1; i++) {
Callable callableImpl = new Callable<Void>(){
public void call(){
//Do something
}
};
Future<Long> completeFuture = executorService.submit(callableImpl);
futureList.add(completeFuture);
}
for (Future<Void> currentTask: futureList) {
if (currentTask.isDone()) {
//Do something
}
}
}
ExecutorService executorService = Executors
.newFixedThreadPool(10);
List<Future<Void>> futureList=new ArrayList<Future<Void>>();
for (int i = 0; i < partNumber - 1; i++) {
Callable callableImpl = new Callable<Void>(){
public void call(){
//Do something
}
};
Future<Long> completeFuture = executorService.submit(callableImpl);
futureList.add(completeFuture);
}
for (Future<Void> currentTask: futureList) {
if (currentTask.isDone()) {
//Do something
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询