com.cometway.util
Class PooledThread

java.lang.Object
  extended by java.lang.Thread
      extended by com.cometway.util.PooledThread
All Implemented Interfaces:
java.lang.Runnable

public class PooledThread
extends java.lang.Thread

This is a Thread used by the ThreadPool class. This thread does not stop until it is no longer needed and is dispoed of. After this thread executes a KMethod (which can wrap a Runnable), Object.wait() is called. The PooledThread will wait until it is notified by Object.notify(), in which case it checks its method field for a KMethod to execute. If an object was passed in through setMethod(), then that object is notified when the execution is complete.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 int id
           
 boolean stopRunning
           
 int threadTimeOut
           
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
PooledThread(ThreadPool pool)
          Creates a new PooledThread.
 
Method Summary
 void run()
          Executes the KMethod.execute(), notifies any object which was waiting, resets state and waits.
 void setMethod(KMethod method)
          This sets the KMethod field of this PooledThread.
 void setMethod(KMethod method, java.lang.Object obj)
          This sets the KMethod and Object fields of this PooledThread.
 
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

stopRunning

public boolean stopRunning

threadTimeOut

public int threadTimeOut

id

public int id
Constructor Detail

PooledThread

public PooledThread(ThreadPool pool)
Creates a new PooledThread. Thread.start() must be called before it can be notified.

Method Detail

setMethod

public void setMethod(KMethod method,
                      java.lang.Object obj)
This sets the KMethod and Object fields of this PooledThread. Afterwards, this PooledThread can be notified and it will execute the KMethod and notify the Object after its execution.


setMethod

public void setMethod(KMethod method)
This sets the KMethod field of this PooledThread. Afterwards, this PooledThread can be notified and it will execute the KMethod.


run

public void run()
Executes the KMethod.execute(), notifies any object which was waiting, resets state and waits.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread