Is an executor object meant to be reused after a shutdown
? I mean if I call shutdown
or shutdownNow
after the executor is terminated, should I do new
to create a new thread pool or is it possible to somehow "reset"/reuse the previously terminated executor and reuse it?
Update:
If I need to create new thread pool, how can I "understand" that the previous has been stopped?
E.g.
The following:
public void startPool(){
if(threadPool != null && !threadPool.isShutdown()){
return;
}
threadPool = Executors.newCachedThreadPool();
//other stuff
}
public void stopPool(){
if(threadPool != null){
threadPool.shutdown();
}
}
Will not work. If I call stop
and then start
a new thread pool will not be created due to conditions. What is the proper way to code this?