How can I guarantee the scheduling by ScheduledThreadPoolExecutor will not die abruptly?

139 views Asked by At

I'm a newbie programmer who's grappling with this issue of ScheduledThreadPoolExecutor.

Upon some googling I got to know how to handle the exceptions from Runnable() part by using afterExecute method. Now it boils to down to this.

What if the ScheduledThreadPoolExecutor's scheduleAtFixedRate() method breaks out an error and the thread stops all of the sudden?

In other words, what if the error is from the Executor class and not from the Runnable implementation?

Is there any way that I can catch errors && deal with it (by restarting the whole scheduling) ?

Thank you

1

There are 1 answers

7
Nir Alfasi On

what if the error is from the Executor class and not from the Runnable implementation?

The error does not come from the executor class.

Is there any way that I can catch errors && deal with it (by restarting the whole scheduling) ?

Yes you can use different techniques to recognize an error and restart ScheduledExecutorService, but the real question should be: is that the right thing to do ?

If you can deal with the error in your Runnable, better deal with it there instead of paying the toll of restarting an Executor.