org.apache.excalibur.thread.impl
Class WorkerThread

java.lang.Object
  |
  +--java.lang.Thread
        |
        +--org.apache.excalibur.thread.impl.WorkerThread
All Implemented Interfaces:
Runnable

public class WorkerThread
extends Thread

This class extends the Thread class to add recyclable functionalities.

Author:
Avalon Development Team, Peter Donald

Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
protected WorkerThread(AbstractThreadPool pool, ThreadGroup group, String name)
          Allocates a new Worker object.
 
Method Summary
 void clearInterruptFlag()
          Clears the interrupt flag for this thread.
protected  void debug(String message)
          Write a debug message.
protected  void debug(String message, Throwable throwable)
          Write a debug message.
 void dispose()
          Set the alive variable to false causing the worker to die.
protected  ThreadControl execute(Executable work)
          Set the Work code this Worker must execute and notifies its thread to do it.
protected  void executeAndWait(Executable work)
          Set the Work code this Worker must execute and notifies its thread to do it.
protected  void postExecute()
          Overide this method to execute something after each bit of "work".
protected  void preExecute()
          Overide this method to execute something before each bit of "work".
protected  void recycleThread()
          Implement this method to replace thread back into pool.
 void run()
          The main execution loop.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, 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

WorkerThread

protected WorkerThread(AbstractThreadPool pool,
                       ThreadGroup group,
                       String name)
Allocates a new Worker object.

Method Detail

run

public final void run()
The main execution loop.

Specified by:
run in interface Runnable
Overrides:
run in class Thread

recycleThread

protected void recycleThread()
Implement this method to replace thread back into pool.


postExecute

protected void postExecute()
Overide this method to execute something after each bit of "work".


preExecute

protected void preExecute()
Overide this method to execute something before each bit of "work".


clearInterruptFlag

public void clearInterruptFlag()
Clears the interrupt flag for this thread. Since Java does not provide a method that does this for an external thread, we have to verify that we are in the WorkerThread. If the code calling this method does not originate from this thread, we set a flag and wait for it to be called internally.


dispose

public void dispose()
Set the alive variable to false causing the worker to die. If the worker is stalled and a timeout generated this call, this method does not change the state of the worker (that must be destroyed in other ways).


execute

protected ThreadControl execute(Executable work)
Set the Work code this Worker must execute and notifies its thread to do it.


executeAndWait

protected void executeAndWait(Executable work)
Set the Work code this Worker must execute and notifies its thread to do it. Wait until the executable has finished before returning.


debug

protected void debug(String message)
Write a debug message. A Noop oin this implementation. Subclasses can overide to actually do some logging.

Parameters:
message - the message to write out

debug

protected void debug(String message,
                     Throwable throwable)
Write a debug message. A Noop oin this implementation. Subclasses can overide to actually do some logging.

Parameters:
message - the message to write out.
throwable - the throwable to write out with the message.


Copyright © 2000-2003 Apache Jakarta Project. All Rights Reserved.