I wrote a small post about this problem a while ago. You have two options:
- Use the solution provided by Colin Herbert or
- use a modified version of Mark Peters solution but instead of assigning a
UncaughtExceptionHandleryou wrap each submitted runnable into a runnable of your own which executes (callsrun) the real runnable inside a try-catch-block.
EDIT
As pointed out by Mark, it’s important to wrap the Runnable passed to ScheduledExecutorService instead of the one passed to the ThreadFactory.