Interface SafeRunnable

  • All Superinterfaces:
    java.lang.Runnable
    All Known Implementing Classes:
    SafeRunnable
    Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface SafeRunnable
    extends java.lang.Runnable
    A runnable that catches runtime exceptions.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.slf4j.Logger LOGGER  
    • Field Detail

      • LOGGER

        static final org.slf4j.Logger LOGGER
    • Method Detail

      • run

        default void run()
        Specified by:
        run in interface java.lang.Runnable
      • safeRun

        void safeRun()
      • safeRun

        static SafeRunnable safeRun​(java.lang.Runnable runnable)
        Utility method to use SafeRunnable from lambdas.

        Eg:

         
         executor.submit(SafeRunnable.safeRun(() -> {
            // My not-safe code
         });
         
         
      • safeRun

        static SafeRunnable safeRun​(java.lang.Runnable runnable,
                                    java.util.function.Consumer<java.lang.Throwable> exceptionHandler)
        Utility method to use SafeRunnable from lambdas with a custom exception handler.

        Eg:

         
         executor.submit(SafeRunnable.safeRun(() -> {
            // My not-safe code
         }, exception -> {
            // Handle exception
         );
         
         
        Parameters:
        runnable -
        exceptionHandler - handler that will be called when there are any exception
        Returns: