Interface SafeRunnable

All Superinterfaces:
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 Runnable
A runnable that catches runtime exceptions.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final org.slf4j.Logger
     
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    run()
     
    void
     
    safeRun(Runnable runnable)
    Utility method to use SafeRunnable from lambdas.
    safeRun(Runnable runnable, Consumer<Throwable> exceptionHandler)
    Utility method to use SafeRunnable from lambdas with a custom exception handler.
  • Field Details

    • LOGGER

      static final org.slf4j.Logger LOGGER
  • Method Details

    • run

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

      void safeRun()
    • safeRun

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

      Eg:

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

      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: