public abstract class WorkerThread
extends java.lang.Thread
Constructor and Description |
---|
WorkerThread()
Construct a worker thread.
|
Modifier and Type | Method and Description |
---|---|
protected void |
cleanup()
Perform any cleanup necessary after work finishes.
|
boolean |
isRunning()
Find out if this thread is still running.
|
void |
kill()
Interrupt any current work, tell the thread to stop and wait for the thread to die.
|
void |
run() |
protected void |
setup()
Perform any setup necessary before work begins.
|
protected abstract boolean |
work()
Do a unit of work and return whether there is more work to be done.
|
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 void kill() throws java.lang.InterruptedException
java.lang.InterruptedException
- If the thread that called kill is itself interrupted.public void run()
run
in interface java.lang.Runnable
run
in class java.lang.Thread
public boolean isRunning()
kill()
has been called (and returned) or if work()
has returned false then this worker thread is not still running.protected abstract boolean work() throws java.lang.InterruptedException
java.lang.InterruptedException
- If the worker thread is interrupted.protected void setup()
protected void cleanup()
work()
method throws an exception. It is highly recommended that this method does not throw any exceptions. Default implementation does nothing.