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

  1. package sun.misc;
  2.  
  3. class TimerTickThread extends Thread {
  4.    static final int MAX_POOL_SIZE = 3;
  5.    static int curPoolSize = 0;
  6.    static TimerTickThread pool = null;
  7.    TimerTickThread next = null;
  8.    Timer timer;
  9.    long lastSleepUntil;
  10.  
  11.    protected static synchronized TimerTickThread call(Timer var0, long var1) {
  12.       TimerTickThread var3 = pool;
  13.       if (var3 == null) {
  14.          var3 = new TimerTickThread();
  15.          var3.timer = var0;
  16.          var3.lastSleepUntil = var1;
  17.          ((Thread)var3).start();
  18.       } else {
  19.          pool = pool.next;
  20.          var3.timer = var0;
  21.          var3.lastSleepUntil = var1;
  22.          synchronized(var3) {
  23.             var3.notify();
  24.          }
  25.       }
  26.  
  27.       return var3;
  28.    }
  29.  
  30.    private boolean returnToPool() {
  31.       Class var1 = this.getClass();
  32.       synchronized(var1) {
  33.          if (curPoolSize >= 3) {
  34.             boolean var10 = false;
  35.             return var10;
  36.          }
  37.  
  38.          this.next = pool;
  39.          pool = this;
  40.          ++curPoolSize;
  41.          this.timer = null;
  42.       }
  43.  
  44.       while(this.timer == null) {
  45.          synchronized(this) {
  46.             try {
  47.                this.wait();
  48.             } catch (InterruptedException var7) {
  49.             }
  50.          }
  51.       }
  52.  
  53.       Class var2 = this.getClass();
  54.       synchronized(var2) {
  55.          --curPoolSize;
  56.          return true;
  57.       }
  58.    }
  59.  
  60.    public void run() {
  61.       do {
  62.          this.timer.owner.tick(this.timer);
  63.          TimerThread var1 = TimerThread.timerThread;
  64.          synchronized(var1) {
  65.             Timer var2 = this.timer;
  66.             synchronized(var2) {
  67.                if (this.lastSleepUntil == this.timer.sleepUntil) {
  68.                   TimerThread.requeue(this.timer);
  69.                }
  70.             }
  71.          }
  72.       } while(this.returnToPool());
  73.  
  74.    }
  75. }
  76.