home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / java / util / Timer.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  2.3 KB  |  118 lines

  1. package java.util;
  2.  
  3. public class Timer {
  4.    private TaskQueue queue = new TaskQueue();
  5.    private TimerThread thread;
  6.    private Object threadReaper;
  7.  
  8.    public Timer() {
  9.       this.thread = new TimerThread(this.queue);
  10.       this.threadReaper = new 1(this);
  11.       this.thread.start();
  12.    }
  13.  
  14.    public Timer(boolean var1) {
  15.       this.thread = new TimerThread(this.queue);
  16.       this.threadReaper = new 1(this);
  17.       this.thread.setDaemon(var1);
  18.       this.thread.start();
  19.    }
  20.  
  21.    public void schedule(TimerTask var1, long var2) {
  22.       if (var2 < 0L) {
  23.          throw new IllegalArgumentException("Negative delay.");
  24.       } else {
  25.          this.sched(var1, System.currentTimeMillis() + var2, 0L);
  26.       }
  27.    }
  28.  
  29.    public void schedule(TimerTask var1, Date var2) {
  30.       this.sched(var1, var2.getTime(), 0L);
  31.    }
  32.  
  33.    public void schedule(TimerTask var1, long var2, long var4) {
  34.       if (var2 < 0L) {
  35.          throw new IllegalArgumentException("Negative delay.");
  36.       } else if (var4 <= 0L) {
  37.          throw new IllegalArgumentException("Non-positive period.");
  38.       } else {
  39.          this.sched(var1, System.currentTimeMillis() + var2, -var4);
  40.       }
  41.    }
  42.  
  43.    public void schedule(TimerTask var1, Date var2, long var3) {
  44.       if (var3 <= 0L) {
  45.          throw new IllegalArgumentException("Non-positive period.");
  46.       } else {
  47.          this.sched(var1, var2.getTime(), -var3);
  48.       }
  49.    }
  50.  
  51.    public void scheduleAtFixedRate(TimerTask var1, long var2, long var4) {
  52.       if (var2 < 0L) {
  53.          throw new IllegalArgumentException("Negative delay.");
  54.       } else if (var4 <= 0L) {
  55.          throw new IllegalArgumentException("Non-positive period.");
  56.       } else {
  57.          this.sched(var1, System.currentTimeMillis() + var2, var4);
  58.       }
  59.    }
  60.  
  61.    public void scheduleAtFixedRate(TimerTask var1, Date var2, long var3) {
  62.       if (var3 <= 0L) {
  63.          throw new IllegalArgumentException("Non-positive period.");
  64.       } else {
  65.          this.sched(var1, var2.getTime(), var3);
  66.       }
  67.    }
  68.  
  69.    private void sched(TimerTask var1, long var2, long var4) {
  70.       if (var2 < 0L) {
  71.          throw new IllegalArgumentException("Illegal execution time.");
  72.       } else {
  73.          TaskQueue var6 = this.queue;
  74.          synchronized(var6) {
  75.             if (!this.thread.newTasksMayBeScheduled) {
  76.                throw new IllegalStateException("Timer already cancelled.");
  77.             } else {
  78.                Object var7 = var1.lock;
  79.                synchronized(var7) {
  80.                   if (var1.state != 0) {
  81.                      throw new IllegalStateException("Task already scheduled or cancelled");
  82.                   }
  83.  
  84.                   var1.nextExecutionTime = var2;
  85.                   var1.period = var4;
  86.                   var1.state = 1;
  87.                }
  88.  
  89.                this.queue.add(var1);
  90.                if (this.queue.getMin() == var1) {
  91.                   this.queue.notify();
  92.                }
  93.  
  94.             }
  95.          }
  96.       }
  97.    }
  98.  
  99.    public void cancel() {
  100.       TaskQueue var1 = this.queue;
  101.       synchronized(var1) {
  102.          this.thread.newTasksMayBeScheduled = false;
  103.          this.queue.clear();
  104.          this.queue.notify();
  105.       }
  106.    }
  107.  
  108.    // $FF: synthetic method
  109.    static TaskQueue access$000(Timer var0) {
  110.       return var0.queue;
  111.    }
  112.  
  113.    // $FF: synthetic method
  114.    static TimerThread access$100(Timer var0) {
  115.       return var0.thread;
  116.    }
  117. }
  118.