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.UncaughtExceptionHandler
MAX_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.
|
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, yield
public 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.
Exception
public 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.
Exception
public void trySync(long timeout) throws Exception
This method blocks like Thread.join()
, but performs an additional check for
exceptions thrown from the go()
method.
Exception
Copyright © 2014–2020 The Apache Software Foundation. All rights reserved.