Class CleanupRunnable

  • All Implemented Interfaces:
    Runnable

    public class CleanupRunnable
    extends Object
    implements Runnable
    A cleanup runnable executes a runnable and afterwards a special cleanup runnable finally after the first runnable. Problems occurring in the cleanup runnable will be logged to the designated logger. This way exceptions from the first runnable will not be swallowed.
    Author:
    Ulrich Kreher
    • Field Detail

      • runnable

        protected final Runnable runnable
        The runnable executed normally.
      • cleanup

        protected final Runnable cleanup
        The cleanup runnable executed after the normal execution has terminated.
      • logger

        protected final Logger logger
        The logger for logging exceptions from the cleanup runnable.
    • Constructor Detail

      • CleanupRunnable

        public CleanupRunnable​(Runnable runnable,
                               Runnable cleanup,
                               Logger logger)
        Creates a new cleanup runnable executing the first runnable and the cleanup runnable finally after the first runnable. Problems occurring in the cleanup runnable will be logged to the designated logger.
        Parameters:
        runnable - The runnable executed normally.
        cleanup - The cleanup runnable executed after the normal execution has terminated.
        logger - The logger for logging exceptions from the cleanup runnable.
    • Method Detail

      • run

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