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| 构造器和说明 |
|---|
CheckedThread()
Unnamed checked thread.
|
CheckedThread(String name)
Checked thread with a name.
|
| 限定符和类型 | 方法和说明 |
|---|---|
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.
|
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.
|
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(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.
Exceptionpublic void sync(long timeout)
throws Exception
Exception is thrown.
This method blocks like Thread.join(), but performs an additional check for exceptions
thrown from the go() method.
Exceptionpublic void trySync(long timeout)
throws Exception
This method blocks like Thread.join(), but performs an additional check for exceptions
thrown from the go() method.
ExceptionCopyright © 2014–2023 The Apache Software Foundation. All rights reserved.