home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / misc / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  2.1 KB  |  133 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.  
  23.       try {
  24.          if (timerThread == null) {
  25.             timerThread = new TimerThread();
  26.          }
  27.       } catch (Throwable var6) {
  28.          throw var6;
  29.       }
  30.  
  31.    }
  32.  
  33.    public synchronized boolean isStopped() {
  34.       return this.stopped;
  35.    }
  36.  
  37.    public void stop() {
  38.       long var1 = System.currentTimeMillis();
  39.       TimerThread var3 = timerThread;
  40.       synchronized(var3) {
  41.          synchronized(this){}
  42.  
  43.          try {
  44.             if (!this.stopped) {
  45.                TimerThread.dequeue(this);
  46.                this.remainingTime = Math.max(0L, this.sleepUntil - var1);
  47.                this.sleepUntil = var1;
  48.                this.stopped = true;
  49.             }
  50.          } catch (Throwable var8) {
  51.             throw var8;
  52.          }
  53.       }
  54.  
  55.    }
  56.  
  57.    public void cont() {
  58.       TimerThread var1 = timerThread;
  59.       synchronized(var1) {
  60.          synchronized(this){}
  61.  
  62.          try {
  63.             if (this.stopped) {
  64.                this.sleepUntil = Math.max(this.sleepUntil + 1L, System.currentTimeMillis() + this.remainingTime);
  65.                TimerThread.enqueue(this);
  66.                this.stopped = false;
  67.             }
  68.          } catch (Throwable var6) {
  69.             throw var6;
  70.          }
  71.       }
  72.  
  73.    }
  74.  
  75.    public void reset() {
  76.       TimerThread var1 = timerThread;
  77.       synchronized(var1) {
  78.          synchronized(this){}
  79.  
  80.          try {
  81.             this.setRemainingTime(this.interval);
  82.          } catch (Throwable var6) {
  83.             throw var6;
  84.          }
  85.       }
  86.  
  87.    }
  88.  
  89.    public synchronized long getStopTime() {
  90.       return this.sleepUntil;
  91.    }
  92.  
  93.    public synchronized long getInterval() {
  94.       return this.interval;
  95.    }
  96.  
  97.    public synchronized void setInterval(long var1) {
  98.       this.interval = var1;
  99.    }
  100.  
  101.    public synchronized long getRemainingTime() {
  102.       return this.remainingTime;
  103.    }
  104.  
  105.    public void setRemainingTime(long var1) {
  106.       TimerThread var3 = timerThread;
  107.       synchronized(var3) {
  108.          synchronized(this){}
  109.  
  110.          try {
  111.             if (this.stopped) {
  112.                this.remainingTime = var1;
  113.             } else {
  114.                this.stop();
  115.                this.remainingTime = var1;
  116.                this.cont();
  117.             }
  118.          } catch (Throwable var8) {
  119.             throw var8;
  120.          }
  121.       }
  122.  
  123.    }
  124.  
  125.    public synchronized void setRegular(boolean var1) {
  126.       this.regular = var1;
  127.    }
  128.  
  129.    protected Thread getTimerThread() {
  130.       return TimerThread.timerThread;
  131.    }
  132. }
  133.