Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.sun.jdmk
Class DaemonTaskServer

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

public class DaemonTaskServer
extends java.lang.Object
implements 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 daemon 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)` Cancel the given task.
`protected void` | `execute(Task task)` Execute the given task.
`void` | `reset()` Reset the DaemonTaskServer.
`void` | `start()` Start the Task Server Thread.
`void` | `start(int threadPriority)` 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

### execute

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

  Execute the given task. This method simply calls `task.run()`. It is provided as a customization hook for subclasses.
  Parameters:
    `task` - The task to execute.
  Throws:
    java.lang.InterruptedException - if the task is interrupted.

### cancel

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

  Cancel the given task. This method simply calls `task.cancel()`. It is provided as a customization hook for subclasses.
  Parameters:
    `task` - The task to cancel.
  Throws:
    java.lang.InterruptedException - if cancel is interrupted.

### 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.
  Throws:
    java.lang.InterruptedException - if stop is interrupted.

### 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, unless `reset()` is called.
  Throws:
    java.lang.InterruptedException - if cancel is interrupted.

### reset

    public void reset()

  Reset the DaemonTaskServer. This method makes it possible to reuse the DaemonTaskServer after a `terminate()`
  Throws:
    java.lang.IllegalStateException - if the DaemonTaskServer is running.

### start

    public void start()

  Start the Task Server Thread.
  Throws:
    java.lang.IllegalStateException - if the DaemonTaskServer is terminated.

### start

    public void start(int threadPriority)

  Start the Task Server Thread. Assign the specified priority to the internal daemon thread.
  Parameters:
    `threadPriority` - Priority of the daemon thread see `Thread`.
  Throws:
    java.lang.IllegalStateException - if the DaemonTaskServer is terminated.

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD