Class sun.server.misc.AlarmManager
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class sun.server.misc.AlarmManager

java.lang.Object
   |
   +----sun.server.misc.AlarmManager

public class AlarmManager
extends Object
implements Runnable
This class implements an alarm event manager. Alarms can be used to schedule events to occur at a specified time in the future. The alarm manager runs in a separate thread to schedule and dispatch alarm events to alarm handlers that implement AlarmHandler. For example, the following example will schedule an alarm event to print out the current time every 5 seconds:
	class AlarmTest implements AlarmHandler {
	    AlarmManager am = new AlarmManager();
	    AlarmTest() {
		new Thread(am).start();
		Alarm a = new Alarm(this);
		a.setTimeFromNow(5 * 1000);
		am.schedule(a);
	    }
	    public void handleAlarm(Alarm a) {
		long time = System.currentTimeMillis();
		System.out.println("Wake up! " + new Date(time).toString());
		a.setTimeFromNow(5 * 1000);
		am.schedule(a);
	    }
	    public static void main(String args[]) {
		new AlarmTest();
	    }
	}
See Also:
Alarm, AlarmHandler

Constructor Index

 o AlarmManager()

Method Index

 o AlarmManager()
Creates a new alarm manager, for managing alarm events.
 o cancel(Alarm)
Cancels a previously scheduled alarm event, removing it from the queue of pending alarm events.
 o cancelAll()
Cancels all previously schedules alarm events.
 o run()
Runs the alarm event manager.
 o schedule(Alarm)
Inserts a new alarm into the alarm event queue.

Constructors

 o AlarmManager
  public AlarmManager()

Methods

 o AlarmManager
  public void AlarmManager()
Creates a new alarm manager, for managing alarm events.
 o run
  public void run()
Runs the alarm event manager.
 o schedule
  public synchronized void schedule(Alarm alarm)
Inserts a new alarm into the alarm event queue. The queue entries are sorted by time in increasing order, so that the alarm at the head of the queue is the next one to process.
Parameters:
alarm - the alarm to schedule
 o cancel
  public synchronized void cancel(Alarm alarm)
Cancels a previously scheduled alarm event, removing it from the queue of pending alarm events.
Parameters:
alarm - the alarm to cancel
 o cancelAll
  public synchronized void cancelAll()
Cancels all previously schedules alarm events.

All Packages  Class Hierarchy  This Package  Previous  Next  Index