nl.knowledgeplaza.util.thread
Class WorkerThread

java.lang.Object
  extended by java.lang.Thread
      extended by nl.knowledgeplaza.util.thread.WorkerThread
All Implemented Interfaces:
java.lang.Runnable

public class WorkerThread
extends java.lang.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 $

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String SOURCECODE_VERSION
          Standard variable for determining version of a class file.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
WorkerThread()
           
WorkerThread(java.lang.String name)
           
 
Method Summary
 void add(java.lang.Runnable r)
          Add a new runnable to the worker thread
 void add(java.lang.String name, java.lang.Runnable r)
          Description for a task
static WorkerThread createAndStart()
           
static WorkerThread createAndStart(boolean override)
           
static WorkerThread createAndStart(java.lang.String name, boolean override)
           
 java.lang.String getActivityDescription()
           
 java.lang.String getActivityDescription(java.lang.String prefix)
           
 boolean getOverride()
           
 boolean isBusy()
          true if this thread still has work to do
static void main(java.lang.String[] args)
           
 void run()
           
 void setOverride(boolean override)
          override will make sure only one runnable is queued at any time
 
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SOURCECODE_VERSION

public static final java.lang.String SOURCECODE_VERSION
Standard variable for determining version of a class file.

See Also:
Constant Field Values
Constructor Detail

WorkerThread

public WorkerThread()

WorkerThread

public WorkerThread(java.lang.String name)
Method Detail

createAndStart

public static WorkerThread createAndStart()

createAndStart

public static WorkerThread createAndStart(boolean override)
Parameters:
override -

createAndStart

public static WorkerThread createAndStart(java.lang.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(java.lang.Runnable r)
Add a new runnable to the worker thread


add

public void add(java.lang.String name,
                java.lang.Runnable r)
Description for a task

Parameters:
name -
r -

getActivityDescription

public java.lang.String getActivityDescription(java.lang.String prefix)
Returns:

getActivityDescription

public java.lang.String getActivityDescription()

run

public void run()
Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

isBusy

public boolean isBusy()
true if this thread still has work to do

Returns:

main

public static void main(java.lang.String[] args)


Copyright © 2010 KnowledgePlaza. All Rights Reserved.