Class WorkerThread

  extended by java.lang.Thread
      extended by de.nava.informa.utils.toolkit.WorkerThread
All Implemented Interfaces:
Direct Known Subclasses:
CleanerWorkerThread, PollerWorkerThread

public abstract class WorkerThread
extends Thread

Abstract worker thread which is driven by WorkersManager. Worker thread runs until terminate property is set to true. All of the threads are run in daemon mode and do not prevent application from sudden quit.

In order to do something useful with channel this class should be extended with implementation of process() method. This method is invoked each time the thread receives new processing task. Current class takes care of getting new tasks, marking busy state and other necessary tasks.

After the task is finished worker checks JobSourceIF object (if specified) to get new assignments and it there's no job goes to sleep for a IDLE_SLEEP_TIME milliseconds. When manager finds new task it immediately awakens the thread. If the thread doesn't receive new assignments for an IDLE_SLEEP_TIME it checks the JobSourceIF object again by itself to find new task. This is done for greater safety reasons to avoid situations when the queue is full of tasks and workers are in endless sleep.

Aleksey Gureev (

Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
Field Summary
Fields inherited from class java.lang.Thread
Constructor Summary
WorkerThread(String name)
          Creates named worker thread.
Method Summary
 ChannelRecord getChannelInProcess()
          Returns channel which is currently in processing.
protected abstract  void processRecord(ChannelRecord record)
          Processes record.
 void run()
          If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 void setQueue(org.apache.commons.collections.Buffer queue)
          Sets the queue of tasks.
 void terminate()
          Marks this thread for termination on job completion.
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

Constructor Detail


public WorkerThread(String name)
Creates named worker thread.

name - name of the thread.
Method Detail


public final void terminate()
Marks this thread for termination on job completion.


public final ChannelRecord getChannelInProcess()
Returns channel which is currently in processing.



public final void run()
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.

Specified by:
run in interface Runnable
run in class Thread
See Also:
Thread.start(), Thread.Thread(ThreadGroup, Runnable, String),


protected abstract void processRecord(ChannelRecord record)
Processes record.

record - record to process.


public void setQueue(org.apache.commons.collections.Buffer queue)
Sets the queue of tasks.

queue - blocking queue of tasks.

Copyright © 2002-2007 Niko Schmuck. All Rights Reserved.