First you have to remove final
access level modifier to re-create ExecutorService
at latter stage. final
modifier does not allow you to change the reference of ExecutorService
later during re-initialization.
In same case I need executor to stop doing his job. For this I call listenDataExecutorService.shutdown();
You have to call three methods in a right sequence to shutdown the ExecutorService
: shutdown, awaitTermination, shutdownNow
Have a look at below post:
How to properly shutdown java ExecutorService
Then after some time, I need this executor to do this job again. But when I call listenDataExecutorService.execute()
exception is thrown.
How can I execute new task for executor after shutdown ?
Before you call execute
on that ExecutorService
, that service should not be in shutdown
state. Make sure that ExecutorService
is in proper state to accept tasks => Your application code should properly handle "shutdown" and "re-creation" of ExecutorService
.