Package org.apache.flink.core.testutils
Class CheckedThread
java.lang.Object
java.lang.Thread
org.apache.flink.core.testutils.CheckedThread
- All Implemented Interfaces:
Runnable
A thread that additionally catches exceptions and offers a joining method that re-throws the
exceptions.
Rather than overriding Thread.run() (or supplying a Runnable), one needs to
extends this class and implement the go() method. That method may throw exceptions.
Exception from the go() method are caught and re-thrown when joining this thread via
the sync() method.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionUnnamed checked thread.CheckedThread(String name) Checked thread with a name. -
Method Summary
Modifier and TypeMethodDescriptionabstract voidgo()This method needs to be overwritten to contain the main work logic.final voidrun()This method is final - thread work should go into thego()method instead.voidsync()Waits until the thread is completed and checks whether any error occurred during the execution.voidsync(long timeout) Waits with timeout until the thread is completed and checks whether any error occurred during the execution.voidtrySync(long timeout) Waits with timeout until the thread is completed and checks whether any error occurred during the execution.Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Constructor Details
-
CheckedThread
public CheckedThread()Unnamed checked thread. -
CheckedThread
Checked thread with a name.- Parameters:
name- the name of the new thread- See Also:
-
-
Method Details
-
go
This method needs to be overwritten to contain the main work logic. It takes the role ofThread.run(), but should propagate exceptions. -
run
public final void run()This method is final - thread work should go into thego()method instead. -
sync
Waits until the thread is completed and checks whether any error occurred during the execution.This method blocks like
Thread.join(), but performs an additional check for exceptions thrown from thego()method.- Throws:
Exception
-
sync
Waits with timeout until the thread is completed and checks whether any error occurred during the execution. In case of timeout anExceptionis thrown.This method blocks like
Thread.join(), but performs an additional check for exceptions thrown from thego()method.- Throws:
Exception
-
trySync
Waits with timeout until the thread is completed and checks whether any error occurred during the execution.This method blocks like
Thread.join(), but performs an additional check for exceptions thrown from thego()method.- Throws:
Exception
-