public abstract class CheckedThread extends Thread
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.
Thread.State, Thread.UncaughtExceptionHandlerMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY| Constructor and Description |
|---|
CheckedThread()
Unnamed checked thread.
|
CheckedThread(String name)
Checked thread with a name.
|
| Modifier and Type | Method and 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 the
go() method instead. |
void |
sync()
Waits until the thread is completed and checks whether any error occurred during
the execution.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yieldpublic CheckedThread()
public CheckedThread(String name)
name - the name of the new threadThread.Thread(String)public abstract void go()
throws Exception
Thread.run(), but should propagate exceptions.public final void run()
go() method instead.public void sync()
throws Exception
This method blocks like Thread.join(), but performs an additional check for
exceptions thrown from the go() method.
ExceptionCopyright © 2014–2017 The Apache Software Foundation. All rights reserved.