Package com.jcabi.log
Class VerboseRunnable
- java.lang.Object
-
- com.jcabi.log.VerboseRunnable
-
- All Implemented Interfaces:
Runnable
public final class VerboseRunnable extends Object implements Runnable
Wrapper ofRunnable
, 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 (usingLogger
). 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.
- Since:
- 0.1.3
- See Also:
VerboseThreads
-
-
Constructor Summary
Constructors Constructor Description VerboseRunnable(Runnable runnable)
Default constructor, doesn't swallow exceptions.VerboseRunnable(Runnable runnable, boolean swallow)
Default constructor, with configurable behavior for exceptions.VerboseRunnable(Runnable runnable, boolean swallow, boolean vrbs)
Default constructor, with fully configurable behavior.VerboseRunnable(Callable<?> callable)
Default constructor, doesn't swallow exceptions.VerboseRunnable(Callable<?> callable, boolean swallow)
Default constructor, doesn't swallow exceptions.VerboseRunnable(Callable<?> callable, boolean swallow, boolean vrbs)
Default constructor.
-
-
-
Constructor Detail
-
VerboseRunnable
public VerboseRunnable(Runnable runnable)
Default constructor, doesn't swallow exceptions.- Parameters:
runnable
- Runnable to wrap
-
VerboseRunnable
public VerboseRunnable(Callable<?> callable)
Default constructor, doesn't swallow exceptions.- Parameters:
callable
- Callable to wrap- Since:
- 0.7.17
-
VerboseRunnable
public VerboseRunnable(Callable<?> callable, boolean swallow)
Default constructor, doesn't swallow exceptions.
-
VerboseRunnable
public VerboseRunnable(Callable<?> callable, boolean swallow, boolean vrbs)
Default constructor.- Parameters:
callable
- Callable to wrapswallow
- Shall we swallow exceptions (TRUE
) or re-throw (FALSE
)? Exception swallowing means thatrun()
will never throw any exceptions (in any case all exceptions are logged usingLogger
.vrbs
- Shall we report the entire stacktrace of the exception (TRUE
) or just its message in one line (FALSE
)- Since:
- 0.7.17
-
VerboseRunnable
public VerboseRunnable(Runnable runnable, boolean swallow)
Default constructor, with configurable behavior for exceptions.
-
VerboseRunnable
public VerboseRunnable(Runnable runnable, boolean swallow, boolean vrbs)
Default constructor, with fully configurable behavior.- Parameters:
runnable
- Runnable to wrapswallow
- Shall we swallow exceptions (TRUE
) or re-throw (FALSE
)? Exception swallowing means thatrun()
will never throw any exceptions (in any case all exceptions are logged usingLogger
.vrbs
- Shall we report the entire stacktrace of the exception (TRUE
) or just its message in one line (FALSE
)- Since:
- 0.7.17
-
-