Package org.apache.flink.core.testutils
Class CheckedThread
- java.lang.Object
-
- java.lang.Thread
-
- org.apache.flink.core.testutils.CheckedThread
-
- All Implemented Interfaces:
Runnable
public abstract class CheckedThread extends Thread
A thread that additionally catches exceptions and offers a joining method that re-throws the exceptions.Rather than overriding
Thread.run()
(or supplying aRunnable
), one needs to extends this class and implement thego()
method. That method may throw exceptions.Exception from the
go()
method are caught and re-thrown when joining this thread via thesync()
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
Constructors Constructor Description CheckedThread()
Unnamed checked thread.CheckedThread(String name)
Checked thread with a name.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
go()
This method needs to be overwritten to contain the main work logic.void
run()
This method is final - thread work should go into thego()
method instead.void
sync()
Waits until the thread is completed and checks whether any error occurred during the execution.void
sync(long timeout)
Waits with timeout until the thread is completed and checks whether any error occurred during the execution.void
trySync(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 Detail
-
CheckedThread
public CheckedThread()
Unnamed checked thread.
-
CheckedThread
public CheckedThread(String name)
Checked thread with a name.- Parameters:
name
- the name of the new thread- See Also:
Thread(String)
-
-
Method Detail
-
go
public abstract void go() throws Exception
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
public void sync() throws Exception
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
public void sync(long timeout) throws Exception
Waits with timeout until the thread is completed and checks whether any error occurred during the execution. In case of timeout anException
is thrown.This method blocks like
Thread.join()
, but performs an additional check for exceptions thrown from thego()
method.- Throws:
Exception
-
trySync
public void trySync(long timeout) throws Exception
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
-
-