Class ExceptionLoggingRunnable

  • All Implemented Interfaces:
    Runnable

    public class ExceptionLoggingRunnable
    extends Object
    implements Runnable
    A runnable catching runtime exceptions and virtual machine errors and optionally rethrowing them.
    • Field Detail

      • runnable

        protected final Runnable runnable
        The wrapped runnable.
      • rethrow

        protected final boolean rethrow
        Whether to rethrow an occurred runtime exception or virtual machine error. In case of a scheduled runnable, rethrowing will stop further executions.
      • logger

        protected final Logger logger
        The logger with which to log an exception.
    • Constructor Detail

      • ExceptionLoggingRunnable

        public ExceptionLoggingRunnable​(Runnable runnable,
                                        boolean rethrow,
                                        Logger logger)
        Wraps the designated runnable to catch and log runtime exceptions and virtual machine errors to the designated logger and optionally rethrowing the runtime exception/virtual machine error. In case of a scheduled runnable, rethrowing will stop further executions.
        Parameters:
        runnable - The wrapped runnable.
        rethrow - Whether to rethrow an occurred runtime exception or virtual machine error.
        logger - The logger with which to log an exception.
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface Runnable