I have a ScheduledThreadPoolExecutor that seems to be eating Exceptions. I want my executor service to notify me if a submitted Runnable throws an exception.
For ex
You could also use a ThreadPoolTaskScheduler
from the Spring Framework, which exposes a method to set an error handler and does all the wrapping for you. The default behavior depends on the type of task:
If the provided ErrorHandler
is not null, it will be used. Otherwise, repeating tasks will have errors suppressed by default whereas one-shot tasks will have errors propagated by default since those errors may be expected through the returned Future
. In both cases, the errors will be logged.
If you only want to use the wrapping part and not the TaskScheduler
you can use
TaskUtils.decorateTaskWithErrorHandler(task, errorHandler, isRepeatingTask)
which the TaskScheduler
uses internally.