Runnable, that logs all uncaught runtime exceptions.
You can use it with scheduled executor, for example:
Executors.newScheduledThreadPool(2).scheduleAtFixedRate( new VerboseRunnable(runnable, true), 1L, 1L, TimeUnit.SECONDS );
Now, every runtime exception that is not caught inside your
Runnable will be reported to log (using
Two-arguments constructor can be used when you need to instruct the class
about what to do with the exception: either swallow it or escalate.
Sometimes it's very important to swallow exceptions. Otherwise an entire
thread may get stuck (like in the example above).
This class is thread-safe.
|Constructor and Description|
Default constructor, doesn't swallow exceptions.
Default constructor, with configurable behavior for exceptions.
public VerboseRunnable(Runnable runnable)
runnable- Runnable to wrap
public VerboseRunnable(Runnable runnable, boolean swlw)
public VerboseRunnable(Callable<?> callable, boolean swlw)
Copyright © 2012 jcabi.com. All Rights Reserved.