com.sun.jdmk
Class DaemonTaskServer

java.lang.Object
  |
  +--com.sun.jdmk.DaemonTaskServer

public class DaemonTaskServer
extends java.lang.Object
implements java.lang.Runnable, TaskServer

This class inplements a Task Server that runs in its own thread. Objects can submit tasks to this object, and they will be executed in background in this object deamon thread. The submitted tasks should not block or last too long - because it will prevent following tasks to be executed. When a task producer calls the submitTask(Task) method, the task is put inside a FIFO list, and the Task Server Thread is woken up, if necessary. After that, the method return.

The Task Server Thread then asynchronously takes the tasks out of the FIFO list, and invokes the run() method.

This mechanism guarantee that the Task producer will spend a minimum time invoking the tasks, and will not be blocked.


Constructor Summary
DaemonTaskServer()
           
 
Method Summary
protected  void cancel(Task task)
           
protected  void execute(Task task)
           
 void reset()
           
 void run()
          Implements the Task Server Thread loop.
 void start()
          Start the Task Server Thread.
 void stop()
          Stop the Task Server Thread.
 void submitTask(Task task)
          Submit a task.
 void terminate()
          Stop the Task Server Thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DaemonTaskServer

public DaemonTaskServer()
Method Detail

run

public void run()
Implements the Task Server Thread loop.
Specified by:
run in interface java.lang.Runnable

execute

protected void execute(Task task)
                throws java.lang.InterruptedException

cancel

protected void cancel(Task task)
               throws java.lang.InterruptedException

submitTask

public void submitTask(Task task)
Submit a task. The submitted task is put inside a FIFO list, and the Task Server Thread is woken up, if necessary. After that, the method returns. The task will be executed asynchronously by the Task Server Thread.
Specified by:
submitTask in interface TaskServer
Parameters:
task - The Task to execute.

stop

public void stop()
          throws java.lang.InterruptedException
Stop the Task Server Thread. Wait for the thread to die.

terminate

public void terminate()
               throws java.lang.InterruptedException
Stop the Task Server Thread. Wait for the thread to die. Then flush the Task FIFO, cancelling any remaining task. During this time, the object will reject any call to submitTask(). When terminated, the object can not be started again.

reset

public void reset()

start

public void start()
Start the Task Server Thread.