A Queue of timed tasks. Each task implements {@link Runnable}. Events can either be executed in the queue's thread or in their own thread.
A task is an object that implements Runnable
. It is scheduled by invoking {@link #schedule(long,Runnable,WakeupManager.ThreadDesc) schedule} with a time at which it should be run. When that timearrives (approximately) the task will be pulled off the queue and have its {@link Runnable#run run} method invoked.
A schedule
request can specify a {@link WakeupManager.ThreadDesc}, which will define the parameters of a thread to be created to run the Runnable
. You can specify the group, whether the thread is a daemon thread, and the priority. Additionally you can use a subclass of WakeupManager.ThreadDesc
and override the {@link WakeupManager.ThreadDesc#thread thread} methodto further customize thread creation.
When a task is scheduled, a {@link WakeupManager.Ticket} is returnedthat can be used to cancel the event if desired.
The queue requires its own thread, whose parameters can be defined via a ThreadDesc
if desired. The queue's thread will be started when the first task is scheduled. If the queue becomes empty the thread will be terminated after a configurable delay. The thread will be re-started if a new task is scheduled.
While it is theoretically possible to obtain the queue's thread and interrupt it, the results of doing so are undefined. If a client wishes to stop the queue's thread the client should either remove all the tasks or call {@link #stop}. Note, calling stop
will cause future schedule
calls to fail with an IllegalStateException
.
WakeupManager
supports the queueThreadTimeout
configuration entry, with the component com.sun.jini.thread.WakeupManager
.
• | queueThreadTimeout |
  | Type: | long |
  | Default: | 30,000 milliseconds |
  | Description: | How long, in milliseconds, the queue's thread will be left running if there are no scheduled tasks. Must be a non-negative long value. This configuration entry is consulted when the WakeupManager is initially created. |
This class uses the {@link Logger} namedcom.sun.jini.thread.WakeupManager
to log information at the following logging levels:
Level | Description |
SEVERE | exceptions thrown when we attempt to create the queue's thread |
WARNING | exceptions thrown by the run methods of tasks, by the ThreadDesc 's of tasks, or if the queue's thread is interrupted |
FINEST | how many milliseconds until the next event and when the queue's thread is stopped or started |
@author Sun Microsystems, Inc.
@see java.lang.Runnable