我怀疑是否java.util.concurrent.ExecutorService
应该在所有任务完成或取消后关闭?
我有这样的方法:
public void testProxies() {
// 5 thread
ExecutorService exec = Executors.newFixedThreadPool(5);
try {
while(condition){
exec.execute(new Runnable() {
@Override
public void run() {
//some task
}
});
}
} catch (Exception e) {
e.printStackTrace();
} finally {
exec.shutdown();// should be shutdown here?
}
}
这是正确的使用方式ExecutorService
吗?
我怎样才能重用ExecutorService
?
ExecutorService
应该关机还是放手?