Class SafeRunnable

java.lang.Object
org.apache.bookkeeper.util.SafeRunnable
All Implemented Interfaces:
Runnable, SafeRunnable

public abstract class SafeRunnable extends Object implements SafeRunnable
A SafeRunnable implementation.
  • Constructor Details

    • SafeRunnable

      public SafeRunnable()
  • Method Details

    • safeRun

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

      Eg:

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

      public static SafeRunnable safeRun(Runnable runnable, Consumer<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: