Package com.jcabi.log
Class VerboseCallable<T>
- java.lang.Object
-
- com.jcabi.log.VerboseCallable<T>
-
- Type Parameters:
T
- Type of result
- All Implemented Interfaces:
Callable<T>
public final class VerboseCallable<T> extends Object implements Callable<T>
Wrapper ofCallable
, that logs all uncaught runtime exceptions.You can use it with scheduled executor, for example:
Executors.newFixedThreadPool(1).submit( new VerboseCallable(callable, true) );
Now, every runtime exception that is not caught inside your
Callable
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.16
- See Also:
VerboseThreads
-
-
Constructor Summary
Constructors Constructor Description VerboseCallable(Runnable runnable, boolean swallow)
Default constructor, with configurable behavior for exceptions.VerboseCallable(Runnable runnable, boolean swallow, boolean vrbs)
Default constructor.VerboseCallable(Callable<T> callable)
Default constructor, doesn't swallow exceptions.VerboseCallable(Callable<T> callable, boolean swallow)
Default constructor, doesn't swallow exceptions.VerboseCallable(Callable<T> callable, boolean swallow, boolean vrbs)
Default constructor, with fully configurable behavior.
-
-
-
Constructor Detail
-
VerboseCallable
public VerboseCallable(Callable<T> callable)
Default constructor, doesn't swallow exceptions.- Parameters:
callable
- Callable to wrap
-
VerboseCallable
public VerboseCallable(Callable<T> callable, boolean swallow)
Default constructor, doesn't swallow exceptions.
-
VerboseCallable
public VerboseCallable(Runnable runnable, boolean swallow, boolean vrbs)
Default constructor.- Parameters:
runnable
- Runnable to wrapswallow
- Shall we swallow exceptions (TRUE
) or re-throw (FALSE
)? Exception swallowing means thatcall()
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
)
-
VerboseCallable
public VerboseCallable(Runnable runnable, boolean swallow)
Default constructor, with configurable behavior for exceptions.
-
VerboseCallable
public VerboseCallable(Callable<T> callable, boolean swallow, boolean vrbs)
Default constructor, with fully configurable behavior.- Parameters:
callable
- Runnable to wrapswallow
- Shall we swallow exceptions (TRUE
) or re-throw (FALSE
)? Exception swallowing means thatcall()
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
)
-
-