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 / TimerThread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  1.1 KB  |  77 lines

  1. package java.util;
  2.  
  3. class TimerThread extends Thread {
  4.    boolean newTasksMayBeScheduled = true;
  5.    private TaskQueue queue;
  6.  
  7.    TimerThread(TaskQueue var1) {
  8.       this.queue = var1;
  9.    }
  10.  
  11.    public void run() {
  12.       try {
  13.          this.mainLoop();
  14.       } finally {
  15.          TaskQueue var3 = this.queue;
  16.          synchronized(var3) {
  17.             this.newTasksMayBeScheduled = false;
  18.             this.queue.clear();
  19.          }
  20.       }
  21.  
  22.    }
  23.  
  24.    private void mainLoop() {
  25.       while(true) {
  26.          try {
  27.             TimerTask var1;
  28.             boolean var2;
  29.             while(true) {
  30.                TaskQueue var3 = this.queue;
  31.                synchronized(var3) {
  32.                   while(this.queue.isEmpty() && this.newTasksMayBeScheduled) {
  33.                      this.queue.wait();
  34.                   }
  35.  
  36.                   if (this.queue.isEmpty()) {
  37.                      return;
  38.                   }
  39.  
  40.                   var1 = this.queue.getMin();
  41.                   Object var8 = var1.lock;
  42.                   long var4;
  43.                   long var6;
  44.                   synchronized(var8) {
  45.                      if (var1.state == 3) {
  46.                         this.queue.removeMin();
  47.                         continue;
  48.                      }
  49.  
  50.                      var4 = System.currentTimeMillis();
  51.                      var6 = var1.nextExecutionTime;
  52.                      if (var2 = var6 <= var4) {
  53.                         if (var1.period == 0L) {
  54.                            this.queue.removeMin();
  55.                            var1.state = 2;
  56.                         } else {
  57.                            this.queue.rescheduleMin(var1.period < 0L ? var4 - var1.period : var6 + var1.period);
  58.                         }
  59.                      }
  60.                   }
  61.  
  62.                   if (!var2) {
  63.                      this.queue.wait(var6 - var4);
  64.                   }
  65.                   break;
  66.                }
  67.             }
  68.  
  69.             if (var2) {
  70.                var1.run();
  71.             }
  72.          } catch (InterruptedException var13) {
  73.          }
  74.       }
  75.    }
  76. }
  77.