java.util
Class TimerThread

java.lang.Object
  extended byjava.lang.Thread
      extended byjava.util.TimerThread
All Implemented Interfaces:
Runnable

class TimerThread
extends Thread

This "helper class" implements the timer's task execution thread, which waits for tasks on the timer queue, executions them when they fire, reschedules repeating tasks, and removes cancelled tasks and spent non-repeating tasks from the queue.


Field Summary
(package private)  boolean newTasksMayBeScheduled
          This flag is set to false by the reaper to inform us that there are no more live references to our Timer object.
private  TaskQueue queue
          Our Timer's queue.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
(package private) TimerThread(TaskQueue queue)
           
 
Method Summary
private  void mainLoop()
          The main timer loop.
 void run()
          If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

newTasksMayBeScheduled

boolean newTasksMayBeScheduled
This flag is set to false by the reaper to inform us that there are no more live references to our Timer object. Once this flag is true and there are no more tasks in our queue, there is no work left for us to do, so we terminate gracefully. Note that this field is protected by queue's monitor!


queue

private TaskQueue queue
Our Timer's queue. We store this reference in preference to a reference to the Timer so the reference graph remains acyclic. Otherwise, the Timer would never be garbage-collected and this thread would never go away.

Constructor Detail

TimerThread

TimerThread(TaskQueue queue)
Method Detail

run

public void run()
Description copied from class: Thread
If this thread was constructed using a separate Runnable run object, then that Runnable object's run method is called; otherwise, this method does nothing and returns.

Subclasses of Thread should override this method.

Specified by:
run in interface Runnable
Overrides:
run in class Thread
See Also:
Thread.start(), Thread.stop(), Thread.Thread(java.lang.ThreadGroup, java.lang.Runnable, java.lang.String), Runnable.run()

mainLoop

private void mainLoop()
The main timer loop. (See class comment.)