nl.knowledgeplaza.util.thread
Class WorkerThread
java.lang.Object
java.lang.Thread
nl.knowledgeplaza.util.thread.WorkerThread
- All Implemented Interfaces:
- Runnable
public class WorkerThread
- extends Thread
This is a basic worker thread.
New runnables can be added to it and they will be executed in sequence.
An exeception in a runnable will not cause the work to abort.
Use the ThreadUtils' setStopFlag to stop the worker thread.
By setting the override property, new runnables are not just added at the end of the queue,
but the queue is emptied before. This ensures that at maximum one runnable is executing,
and one is queued, because already running runnables are allowed to finish normally.
This is useful for situation where screen contents is refreshing using this class,
but a new refresh is needed before the 1st completes (so the 2nd will be queued),
and a 3rd refresh is needed.
The 1st and 2nd refresh actually are useless, since they will be overriden with the 3rd.
The 1st is already executing, so not much can be done there, but when replace is true,
the 2nd will be removed from the queue and the 3rd inserted.
- Version:
- $Revision: 1.4 $
| Methods inherited from class java.lang.Thread |
activeCount, checkAccess, 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 |
SOURCECODE_VERSION
public static final String SOURCECODE_VERSION
- Standard variable for determining version of a class file.
- See Also:
- Constant Field Values
WorkerThread
public WorkerThread()
WorkerThread
public WorkerThread(String name)
createAndStart
public static WorkerThread createAndStart()
createAndStart
public static WorkerThread createAndStart(boolean override)
- Parameters:
override -
createAndStart
public static WorkerThread createAndStart(String name,
boolean override)
- Parameters:
name - override -
setOverride
public void setOverride(boolean override)
- override will make sure only one runnable is queued at any time
getOverride
public boolean getOverride()
add
public void add(Runnable r)
- Add a new runnable to the worker thread
add
public void add(String name,
Runnable r)
- Description for a task
- Parameters:
name - r -
getActivityDescription
public String getActivityDescription(String prefix)
- Returns:
getActivityDescription
public String getActivityDescription()
run
public void run()
- Specified by:
run in interface Runnable- Overrides:
run in class Thread
isBusy
public boolean isBusy()
- true if this thread still has work to do
- Returns:
main
public static void main(String[] args)
Copyright © 2012 KnowledgePlaza. All Rights Reserved.