I have a ExecutorService
:
private final ExecutorService listenDataExecutorService =
Executors.newSingleThreadExecutor();
In same case I need executor to stop doing his job.
For this I call listenDataExecutorService.shutdown();
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
?
Once an executor service has been shut down it can't be reactivated. Create a new executor service to restart execution:
listenDataExecutorService = Executors.newSingleThreadExecutor();
(You'd have to drop the final
modifier though.)
Another option is to cancel all pending tasks instead, and then reschedule them when you want to resume execution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With