com.boylesoftware.cb2.util.pool
Class PooledThread

java.lang.Object
  extended bycom.boylesoftware.cb2.util.pool.PooledThread
All Implemented Interfaces:
java.lang.Runnable

public abstract class PooledThread
extends java.lang.Object
implements java.lang.Runnable

Abstract parent class for threads to be used with PooledThreadFactory class. The thread sleeps most of the time and calling doExecute method from another thread triggers the user-implemented execute method call from within the pooled thread. After the execute method returns the thread returns itself to the pool and goes into the sleep mode again.

Note, you should not return the thread back to the pool, it does it automatically after the user-defined execute method returns.

The two thread control methods, doExecute and kill should only be called on instances just taken from the pool. That is you call get method on the pool to get an instance and then call one of the control methods once.

Version:
$Id: PooledThread.java,v 1.4 2003/07/30 14:07:50 levahim Exp $
Author:
Lev Himmelfarb

Constructor Summary
PooledThread()
           
 
Method Summary
 void doExecute()
          Triggers the user-defined execute method call.
protected abstract  void execute()
          Define this method and implement the thread's logic in it.
 void kill()
          Kills the thread.
 void run()
          The thread enrty point.
 void setPool(AdaptiveObjectPool pool)
          This method is automatically called from the factory, it sets the internal reference to the pool so this implementation can return objects after execution.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PooledThread

public PooledThread()
Method Detail

setPool

public final void setPool(AdaptiveObjectPool pool)
This method is automatically called from the factory, it sets the internal reference to the pool so this implementation can return objects after execution.

Parameters:
pool - reference to the pool this thread belongs to.

run

public final void run()
The thread enrty point. This method contains the main sleep/execute loop.

Specified by:
run in interface java.lang.Runnable

doExecute

public final void doExecute()
Triggers the user-defined execute method call. Note, that this method does nothing if the thread is already in the user-defined execute.


kill

public final void kill()
Kills the thread. If the thread is executing the user-defined execute method it will not be destroyed until the execute method finishes and returns. Note, that you should call this method only on instances just returned from the pool (the get method on the pool) and never immediately after doExecute call.


execute

protected abstract void execute()
Define this method and implement the thread's logic in it. This method is called each time the doExecute triggering method is called from another thread.



Copyright © 2002,2003,2004 - Boyle Software, Inc.