Class InterruptionChecker


  • public class InterruptionChecker
    extends java.lang.Object
    Check if this thread or any other thread that shares this InterruptionChecker instance has been interrupted or has thrown an exception.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.concurrent.atomic.AtomicBoolean interrupted
      Set to true when a thread is interrupted.
      private java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ExecutionException> thrownExecutionException
      The first ExecutionException that was thrown.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void check()
      Check if this thread or any other thread that shares this InterruptionChecker instance has been interrupted or has thrown an exception, and if so, throw InterruptedException.
      boolean checkAndReturn()
      Check for interruption and return interruption status.
      static java.lang.Throwable getCause​(java.lang.Throwable throwable)
      Get the cause of an ExecutionException.
      java.util.concurrent.ExecutionException getExecutionException()
      Get the ExecutionException that was thrown by a worker, or null if none.
      void interrupt()
      Interrupt all threads that share this InterruptionChecker.
      void setExecutionException​(java.util.concurrent.ExecutionException executionException)
      Set the ExecutionException that was thrown by a worker.
      • Methods inherited from class java.lang.Object

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

      • interrupted

        private final java.util.concurrent.atomic.AtomicBoolean interrupted
        Set to true when a thread is interrupted.
      • thrownExecutionException

        private final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ExecutionException> thrownExecutionException
        The first ExecutionException that was thrown.
    • Constructor Detail

      • InterruptionChecker

        public InterruptionChecker()
    • Method Detail

      • interrupt

        public void interrupt()
        Interrupt all threads that share this InterruptionChecker.
      • setExecutionException

        public void setExecutionException​(java.util.concurrent.ExecutionException executionException)
        Set the ExecutionException that was thrown by a worker.
        Parameters:
        executionException - the execution exception that was thrown
      • getExecutionException

        public java.util.concurrent.ExecutionException getExecutionException()
        Get the ExecutionException that was thrown by a worker, or null if none.
        Returns:
        the ExecutionException that was thrown by a worker, or null if none.
      • getCause

        public static java.lang.Throwable getCause​(java.lang.Throwable throwable)
        Get the cause of an ExecutionException.
        Parameters:
        throwable - the Throwable
        Returns:
        the cause
      • checkAndReturn

        public boolean checkAndReturn()
        Check for interruption and return interruption status.
        Returns:
        true if this thread or any other thread that shares this InterruptionChecker instance has been interrupted or has thrown an exception.
      • check

        public void check()
                   throws java.lang.InterruptedException,
                          java.util.concurrent.ExecutionException
        Check if this thread or any other thread that shares this InterruptionChecker instance has been interrupted or has thrown an exception, and if so, throw InterruptedException.
        Throws:
        java.lang.InterruptedException - If a thread has been interrupted.
        java.util.concurrent.ExecutionException - if a thread has thrown an uncaught exception.