org.objectweb.dream.control.activity.task.thread
Class ThreadPoolTask

java.lang.Object
  extended byorg.objectweb.dream.AbstractComponent
      extended byorg.objectweb.dream.control.activity.task.thread.AbstractThreadTask
          extended byorg.objectweb.dream.control.activity.task.thread.ThreadPoolTask
All Implemented Interfaces:
BindingController, LifeCycleController, Loggable, Task, TaskLifeCycleController, ThreadPoolController

public class ThreadPoolTask
extends AbstractThreadTask
implements TaskLifeCycleController, ThreadPoolController

Thread Pool implementation. In a thread pool, many threads call concurrently the scheduler. The number of threads can be controlled by the ThreadPoolControllercontrol interface.


Field Summary
 
Fields inherited from class org.objectweb.dream.control.activity.task.thread.AbstractThreadTask
scheduler
 
Fields inherited from class org.objectweb.dream.AbstractComponent
bindingLogger, componentDesc, fcState, firstStart, lifeCycleLogger, logger, weaveableC
 
Fields inherited from interface org.objectweb.fractal.api.control.LifeCycleController
STARTED, STOPPED
 
Fields inherited from interface org.objectweb.dream.control.activity.task.thread.ThreadPoolController
DEFAULT_WAIT_TIMEOUT
 
Fields inherited from interface org.objectweb.dream.control.activity.task.Task
ITF_NAME
 
Constructor Summary
ThreadPoolTask()
           
 
Method Summary
 void addThreads(int i)
          Adds threads in the pool.
 void asyncStop(TaskStoppedListener listener)
          Stops asynchronously the task, this interface belong.
 int getCapacity()
          Returns the capacity of the pool.
 int getNbActiveThreads()
          Returns the number of currently active threads.
 long getWaitTimeout()
          Returns the timeout while "dying" thread can be "reactivated".
protected  void interruptPool()
           
protected  boolean isExecuting()
          Called by AbstractThreadTask.execute(Object)method.
 void removeThreads(int i)
          Removes threads from the pool.
 void setCapacity(int i)
          Sets the capacity of the pool.
protected  void setExecuting(boolean b)
          Called by AbstractThreadTask.execute(Object)method.
 void setWaitTimeout(long millis)
          Sets the timeout while a "dying" thread can be "reactivated" and reused, rather than create a new thread.
 void startFc()
           
 void stopFc()
           
 
Methods inherited from class org.objectweb.dream.control.activity.task.thread.AbstractThreadTask
bindFc, execute, listFc, unbindFc
 
Methods inherited from class org.objectweb.dream.AbstractComponent
beforeFirstStart, getFcState, initComponent, lookupFc, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.objectweb.fractal.api.control.LifeCycleController
getFcState
 

Constructor Detail

ThreadPoolTask

public ThreadPoolTask()
Method Detail

isExecuting

protected boolean isExecuting()
Description copied from class: AbstractThreadTask
Called by AbstractThreadTask.execute(Object)method.

Specified by:
isExecuting in class AbstractThreadTask
Returns:
false if the AbstractThreadTask.execute(Object)method must return.
See Also:
AbstractThreadTask.isExecuting()

setExecuting

protected void setExecuting(boolean b)
Description copied from class: AbstractThreadTask
Called by AbstractThreadTask.execute(Object)method. Sets its execution state.

Specified by:
setExecuting in class AbstractThreadTask
Parameters:
b - false if the AbstractThreadTask.execute(Object)method must return.
See Also:
AbstractThreadTask.setExecuting(boolean)

getNbActiveThreads

public int getNbActiveThreads()
Description copied from interface: ThreadPoolController
Returns the number of currently active threads.

Specified by:
getNbActiveThreads in interface ThreadPoolController
Returns:
the number of currently active threads.
See Also:
ThreadPoolController.getNbActiveThreads()

addThreads

public void addThreads(int i)
                throws ThreadPoolOverflowException,
                       IllegalLifeCycleException
Description copied from interface: ThreadPoolController
Adds threads in the pool. If the thread pool is stopping (see TaskLifeCycleController) the added threads are immediatly interrupted.

Specified by:
addThreads in interface ThreadPoolController
Parameters:
i - the number of thread to add.
Throws:
IllegalLifeCycleException - if the component this interface belong has a lifecycle controller and is in the LifeCycleController.STOPPED state.
ThreadPoolOverflowException - if getNbActiveThread() + i > getCapacity()
See Also:
ThreadPoolController.addThreads(int)

removeThreads

public void removeThreads(int i)
                   throws IllegalLifeCycleException
Description copied from interface: ThreadPoolController
Removes threads from the pool. The threads are removed in a FIFO order. This method is not synchronized with the end of the removed threads. This means that the method may return before the end of the removed threads.

Specified by:
removeThreads in interface ThreadPoolController
Parameters:
i - the number of thread to remove.
Throws:
IllegalLifeCycleException - if the component this interface belong has a lifecycle controller and is in the LifeCycleController.STOPPED state.
See Also:
ThreadPoolController.removeThreads(int)

setCapacity

public void setCapacity(int i)
Description copied from interface: ThreadPoolController
Sets the capacity of the pool. The capacity of the pool is the maximum number of currently executing threads. If the capacity is reduced, currently executing threads are not stopped. As a consequence, the number of executing threads may temporarily exceed the capacity.

Specified by:
setCapacity in interface ThreadPoolController
Parameters:
i - the capacity of the pool.
See Also:
ThreadPoolController.setCapacity(int)

getCapacity

public int getCapacity()
Description copied from interface: ThreadPoolController
Returns the capacity of the pool.

Specified by:
getCapacity in interface ThreadPoolController
Returns:
the capacity of the pool.
See Also:
ThreadPoolController.getCapacity()

getWaitTimeout

public long getWaitTimeout()
Description copied from interface: ThreadPoolController
Returns the timeout while "dying" thread can be "reactivated".

Specified by:
getWaitTimeout in interface ThreadPoolController
Returns:
timeout in millisecond.
See Also:
ThreadPoolController.getWaitTimeout()

setWaitTimeout

public void setWaitTimeout(long millis)
Description copied from interface: ThreadPoolController
Sets the timeout while a "dying" thread can be "reactivated" and reused, rather than create a new thread.

Specified by:
setWaitTimeout in interface ThreadPoolController
Parameters:
millis - timeout in millisecond.
See Also:
ThreadPoolController.setWaitTimeout(long)

startFc

public void startFc()
             throws IllegalLifeCycleException
Specified by:
startFc in interface LifeCycleController
Overrides:
startFc in class AbstractComponent
Throws:
IllegalLifeCycleException
See Also:
LifeCycleController.startFc()

stopFc

public void stopFc()
            throws IllegalLifeCycleException
Specified by:
stopFc in interface LifeCycleController
Overrides:
stopFc in class AbstractComponent
Throws:
IllegalLifeCycleException
See Also:
LifeCycleController.stopFc()

asyncStop

public void asyncStop(TaskStoppedListener listener)
Description copied from interface: TaskLifeCycleController
Stops asynchronously the task, this interface belong. This method returns immediatly. The given listener will be notified when the task has stopped. If the task is already in the LifeCycleController.STOPPEDstate, the listener is immediatly notified.

Specified by:
asyncStop in interface TaskLifeCycleController
Parameters:
listener - listener nitified when the task has stopped.
See Also:
TaskLifeCycleController.asyncStop(TaskStoppedListener)

interruptPool

protected void interruptPool()


Copyright © 2003, 2004 - INRIA Rhone-Alpes - All Rights Reserved.