home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / misc / TimerTickThread.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  1.4 KB  |  71 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.          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.       synchronized(this.getClass()) {
  32.          if (curPoolSize >= 3) {
  33.             return false;
  34.          }
  35.  
  36.          this.next = pool;
  37.          pool = this;
  38.          ++curPoolSize;
  39.          this.timer = null;
  40.       }
  41.  
  42.       while(this.timer == null) {
  43.          synchronized(this) {
  44.             try {
  45.                this.wait();
  46.             } catch (InterruptedException var6) {
  47.             }
  48.          }
  49.       }
  50.  
  51.       synchronized(this.getClass()) {
  52.          --curPoolSize;
  53.          return true;
  54.       }
  55.    }
  56.  
  57.    public void run() {
  58.       do {
  59.          this.timer.owner.tick(this.timer);
  60.          synchronized(TimerThread.timerThread) {
  61.             synchronized(this.timer) {
  62.                if (this.lastSleepUntil == this.timer.sleepUntil) {
  63.                   TimerThread.requeue(this.timer);
  64.                }
  65.             }
  66.          }
  67.       } while(this.returnToPool());
  68.  
  69.    }
  70. }
  71.