Class SafeRunnable

  • All Implemented Interfaces:
    java.lang.Runnable, SafeRunnable

    public abstract class SafeRunnable
    extends java.lang.Object
    implements SafeRunnable
    A SafeRunnable implementation.
    • Field Summary

    • Constructor Summary

      Constructors 
      Constructor Description
      SafeRunnable()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static SafeRunnable safeRun​(java.lang.Runnable runnable)
      Utility method to use SafeRunnable from lambdas.
      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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • SafeRunnable

        public SafeRunnable()
    • Method Detail

      • safeRun

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

        Eg:

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

        public 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: