FileDocCategorySizeDatePackage
Timer.javaAPI DocExample7625Sat Jan 24 10:44:26 GMT 2004je3.thread

Timer

public class Timer extends Object
This class is a simple implementation of the Java 1.3 java.util.Timer API

Fields Summary
SortedSet
tasks
TimerThread
timer
Constructors Summary
public Timer()
This constructor create a Timer that does not use a daemon thread


                 
       this(false); 
public Timer(boolean isDaemon)
The main constructor: the internal thread is a daemon if specified

	timer = new TimerThread(isDaemon);  // TimerThread is defined below
	timer.start();                      // Start the thread running
    
Methods Summary
public voidcancel()
Stop the timer thread, and discard all scheduled tasks

	synchronized(tasks) {     // Only one thread at a time!
	    timer.pleaseStop();   // Set a flag asking the thread to stop
	    tasks.clear();        // Discard all tasks
	    tasks.notify();       // Wake up the thread if it is in wait().
	}
    
voidschedule(TimerTask task)

	synchronized(tasks) {  // Only one thread can modify tasks at a time!
	    tasks.add(task);   // Add the task to the sorted set of tasks
	    tasks.notify();    // Wake up the thread if it is waiting
	}
    
public voidschedule(TimerTask task, long delay)
Schedule a single execution after delay milliseconds

	task.schedule(System.currentTimeMillis() + delay, 0, false);
	schedule(task);
    
public voidschedule(TimerTask task, java.util.Date time)
Schedule a single execution at the specified time

	task.schedule(time.getTime(), 0, false);
	schedule(task);
    
public voidschedule(TimerTask task, java.util.Date firstTime, long period)
Schedule a periodic execution starting at the specified time

	task.schedule(firstTime.getTime(), period, false);
	schedule(task);
    
public voidschedule(TimerTask task, long delay, long period)
Schedule a periodic execution starting after the specified delay

	task.schedule(System.currentTimeMillis() + delay, period, false);
	schedule(task);
    
public voidscheduleAtFixedRate(TimerTask task, long delay, long period)
Schedule a periodic execution starting after the specified delay. Schedule fixed-rate executions period ms after the start of the last. Instead of fixed-interval executions measured from the end of the last.

	task.schedule(System.currentTimeMillis() + delay, period, true);
	schedule(task);
    
public voidscheduleAtFixedRate(TimerTask task, java.util.Date firstTime, long period)
Schedule a periodic execution starting after the specified time

	task.schedule(firstTime.getTime(), period, true);
	schedule(task);