Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

iiuf.util
Class Timer  view Timer download Timer.java

java.lang.Object
  extended byiiuf.util.Timer
All Implemented Interfaces:
java.lang.Runnable, java.io.Serializable
Direct Known Subclasses:
TestTimer

public class Timer
extends java.lang.Object
implements java.lang.Runnable, java.io.Serializable

The timer class. This class implements timer tasks that can be run at a specified time. This class stores tasks in an efficient tree representation which keeps the insert and remove costs almost constant even for a large (> 10000) number of tasks. (c) 1999, 2000, 2001, IIUF, DIUF

Version:
$Revision: 1.1 $

Field Summary
 long absolute
           
(package private)  boolean dontRun
          If true, the timer's run will not be called.
protected  boolean execute
          Set to true as soon as the run method starts executing.
 long milliseconds
           
protected  Timer next
          The link to the next timer.
private static java.util.Random random
           
protected  boolean thread
           
private  java.lang.Runnable timer_task
          The task to run by this timer, or null if no task.
 
Constructor Summary
protected Timer()
           
protected Timer(boolean thread_)
           
  Timer(java.lang.Runnable timer_task_, boolean thread)
          Creates a new timer task.
 
Method Summary
 Timer cancel()
          Cancels this timer.
private static void countdown(int sec)
           
static void main(java.lang.String[] argv)
          Test program.
 Timer reschedule()
          Re-schedules this objects run method to be executed in milliseconds_ after the schedule call from the last execution of the run method.
private static int rnd(int range)
           
 void run()
          This method will be called by whoever wishes to run your class implementing Runnable.
 Timer schedule(long milliseconds_)
          Schedules this objects run method to be executed in milliseconds_ from now.
 java.lang.String toString()
          Convert this Object to a human-readable String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

milliseconds

public long milliseconds

absolute

public long absolute

next

protected transient Timer next
The link to the next timer.


execute

protected transient boolean execute
Set to true as soon as the run method starts executing. reset by reschedule or schedule.


thread

protected boolean thread

timer_task

private transient java.lang.Runnable timer_task
The task to run by this timer, or null if no task.


dontRun

transient boolean dontRun
If true, the timer's run will not be called. This variable is set to false by TimerTree.insert() and set by TimerTree.remove().


random

private static java.util.Random random
Constructor Detail

Timer

protected Timer()

Timer

protected Timer(boolean thread_)

Timer

public Timer(java.lang.Runnable timer_task_,
             boolean thread)
Creates a new timer task.

Method Detail

schedule

public Timer schedule(long milliseconds_)
Schedules this objects run method to be executed in milliseconds_ from now.


cancel

public Timer cancel()
Cancels this timer. Cancel only ensures that the run method is not executed after cancel returns. But the run method may be excuted during the execution of cancel.


reschedule

public Timer reschedule()
Re-schedules this objects run method to be executed in milliseconds_ after the schedule call from the last execution of the run method. Use this call for fixed frequency tasks instead of using schedule in order to avoid drift.


toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


run

public void run()
Description copied from interface: java.lang.Runnable
This method will be called by whoever wishes to run your class implementing Runnable. Note that there are no restrictions on what you are allowed to do in the run method, except that you cannot throw a checked exception.

Specified by:
run in interface java.lang.Runnable

rnd

private static int rnd(int range)

countdown

private static void countdown(int sec)

main

public static void main(java.lang.String[] argv)
Test program.