Class InterruptionChecker
- java.lang.Object
-
- nonapi.io.github.classgraph.concurrency.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 firstExecutionException
that was thrown.
-
Constructor Summary
Constructors Constructor Description InterruptionChecker()
-
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 anExecutionException
.java.util.concurrent.ExecutionException
getExecutionException()
Get theExecutionException
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 theExecutionException
that was thrown by a worker.
-
-
-
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 firstExecutionException
that was thrown.
-
-
Method Detail
-
interrupt
public void interrupt()
Interrupt all threads that share this InterruptionChecker.
-
setExecutionException
public void setExecutionException(java.util.concurrent.ExecutionException executionException)
Set theExecutionException
that was thrown by a worker.- Parameters:
executionException
- the execution exception that was thrown
-
getExecutionException
public java.util.concurrent.ExecutionException getExecutionException()
Get theExecutionException
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 anExecutionException
.- 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.
-
-