javax.swing
Class TimerQueue

java.lang.Object
  extended byjavax.swing.TimerQueue
All Implemented Interfaces:
Runnable

class TimerQueue
extends Object
implements Runnable

Internal class to manage all Timers using one thread. TimerQueue manages a queue of Timers. The Timers are chained together in a linked list sorted by the order in which they will expire.

Author:
Dave Moore

Field Summary
private static Object classLock
           
private static Object expiredTimersKey
           
(package private)  Timer firstTimer
           
(package private)  boolean running
           
private static Object sharedInstanceKey
           
 
Constructor Summary
TimerQueue()
          Constructor for TimerQueue.
 
Method Summary
(package private)  void addTimer(Timer timer, long expirationTime)
           
(package private)  boolean containsTimer(Timer timer)
           
(package private)  long postExpiredTimers()
          If there are a ton of timers, this method may never return.
(package private)  void removeTimer(Timer timer)
           
 void run()
          When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
static TimerQueue sharedInstance()
           
(package private)  void start()
           
(package private)  void stop()
           
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

sharedInstanceKey

private static final Object sharedInstanceKey

expiredTimersKey

private static final Object expiredTimersKey

firstTimer

Timer firstTimer

running

boolean running

classLock

private static final Object classLock
Constructor Detail

TimerQueue

public TimerQueue()
Constructor for TimerQueue.

Method Detail

sharedInstance

public static TimerQueue sharedInstance()

start

void start()

stop

void stop()

addTimer

void addTimer(Timer timer,
              long expirationTime)

removeTimer

void removeTimer(Timer timer)

containsTimer

boolean containsTimer(Timer timer)

postExpiredTimers

long postExpiredTimers()
If there are a ton of timers, this method may never return. It loops checking to see if the head of the Timer list has expired. If it has, it posts the Timer and reschedules it if necessary.


run

public void run()
Description copied from interface: Runnable
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

The general contract of the method run is that it may take any action whatsoever.

Specified by:
run in interface Runnable
See Also:
Thread.run()

toString

public String toString()
Description copied from class: Object
Returns a string representation of the object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read. It is recommended that all subclasses override this method.

The toString method for class Object returns a string consisting of the name of the class of which the object is an instance, the at-sign character `@', and the unsigned hexadecimal representation of the hash code of the object. In other words, this method returns a string equal to the value of:

 getClass().getName() + '@' + Integer.toHexString(hashCode())
 

Overrides:
toString in class Object
Returns:
a string representation of the object.