home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &… the Search for Life CD 3 / 0_CD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / misc / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.7 KB  |  113 lines

  1. package sun.misc;
  2.  
  3. public class Timer {
  4.    public Timeable owner;
  5.    long interval;
  6.    long sleepUntil;
  7.    long remainingTime;
  8.    boolean regular;
  9.    boolean stopped;
  10.    Timer next;
  11.    static TimerThread timerThread = null;
  12.  
  13.    public Timer(Timeable var1, long var2) {
  14.       this.owner = var1;
  15.       this.interval = var2;
  16.       this.remainingTime = var2;
  17.       this.regular = true;
  18.       this.sleepUntil = System.currentTimeMillis();
  19.       this.stopped = true;
  20.       Class var4 = this.getClass();
  21.       synchronized(var4) {
  22.          if (timerThread == null) {
  23.             timerThread = new TimerThread();
  24.          }
  25.  
  26.       }
  27.    }
  28.  
  29.    public synchronized boolean isStopped() {
  30.       return this.stopped;
  31.    }
  32.  
  33.    public void stop() {
  34.       long var1 = System.currentTimeMillis();
  35.       TimerThread var3 = timerThread;
  36.       synchronized(var3) {
  37.          synchronized(this) {
  38.             if (!this.stopped) {
  39.                TimerThread.dequeue(this);
  40.                this.remainingTime = Math.max(0L, this.sleepUntil - var1);
  41.                this.sleepUntil = var1;
  42.                this.stopped = true;
  43.             }
  44.          }
  45.  
  46.       }
  47.    }
  48.  
  49.    public void cont() {
  50.       TimerThread var1 = timerThread;
  51.       synchronized(var1) {
  52.          synchronized(this) {
  53.             if (this.stopped) {
  54.                this.sleepUntil = Math.max(this.sleepUntil + 1L, System.currentTimeMillis() + this.remainingTime);
  55.                TimerThread.enqueue(this);
  56.                this.stopped = false;
  57.             }
  58.          }
  59.  
  60.       }
  61.    }
  62.  
  63.    public void reset() {
  64.       TimerThread var1 = timerThread;
  65.       synchronized(var1) {
  66.          synchronized(this) {
  67.             this.setRemainingTime(this.interval);
  68.          }
  69.  
  70.       }
  71.    }
  72.  
  73.    public synchronized long getStopTime() {
  74.       return this.sleepUntil;
  75.    }
  76.  
  77.    public synchronized long getInterval() {
  78.       return this.interval;
  79.    }
  80.  
  81.    public synchronized void setInterval(long var1) {
  82.       this.interval = var1;
  83.    }
  84.  
  85.    public synchronized long getRemainingTime() {
  86.       return this.remainingTime;
  87.    }
  88.  
  89.    public void setRemainingTime(long var1) {
  90.       TimerThread var3 = timerThread;
  91.       synchronized(var3) {
  92.          synchronized(this) {
  93.             if (this.stopped) {
  94.                this.remainingTime = var1;
  95.             } else {
  96.                this.stop();
  97.                this.remainingTime = var1;
  98.                this.cont();
  99.             }
  100.          }
  101.  
  102.       }
  103.    }
  104.  
  105.    public synchronized void setRegular(boolean var1) {
  106.       this.regular = var1;
  107.    }
  108.  
  109.    protected Thread getTimerThread() {
  110.       return TimerThread.timerThread;
  111.    }
  112. }
  113.