home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1999 April / DPPCPRO0499.ISO / April / Notes / 50b2wic.exe / DATA1.CAB / NotesProgramFilesJavaSupport / rt.jar / sun / misc / TimerThread.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-04-23  |  2.8 KB  |  140 lines

  1. package sun.misc;
  2.  
  3. class TimerThread extends Thread {
  4.    public static boolean debug;
  5.    static TimerThread timerThread;
  6.    static boolean notified;
  7.    static Timer timerQueue = null;
  8.  
  9.    protected TimerThread() {
  10.       super("TimerThread");
  11.       timerThread = this;
  12.       ((Thread)this).start();
  13.    }
  14.  
  15.    public synchronized void run() {
  16.       while(true) {
  17.          if (timerQueue != null) {
  18.             notified = false;
  19.             long var1 = timerQueue.sleepUntil - System.currentTimeMillis();
  20.             if (var1 > 0L) {
  21.                try {
  22.                   this.wait(var1);
  23.                } catch (InterruptedException var7) {
  24.                }
  25.             }
  26.  
  27.             if (!notified) {
  28.                Timer var3 = timerQueue;
  29.                timerQueue = timerQueue.next;
  30.                TimerTickThread var4 = TimerTickThread.call(var3, var3.sleepUntil);
  31.                if (debug) {
  32.                   long var5 = System.currentTimeMillis() - var3.sleepUntil;
  33.                   System.out.println("tick(" + ((Thread)var4).getName() + "," + var3.interval + "," + var5 + ")");
  34.                   if (var5 > 250L) {
  35.                      System.out.println("*** BIG DELAY ***");
  36.                   }
  37.                }
  38.             }
  39.          } else {
  40.             try {
  41.                this.wait();
  42.             } catch (InterruptedException var8) {
  43.             }
  44.          }
  45.       }
  46.    }
  47.  
  48.    protected static void enqueue(Timer var0) {
  49.       Object var1 = null;
  50.       Timer var2 = timerQueue;
  51.       if (var2 != null && var0.sleepUntil > var2.sleepUntil) {
  52.          while(true) {
  53.             Timer var7 = var2;
  54.             var2 = var2.next;
  55.             if (var2 == null || var0.sleepUntil <= var2.sleepUntil) {
  56.                var0.next = var2;
  57.                var7.next = var0;
  58.                break;
  59.             }
  60.          }
  61.       } else {
  62.          var0.next = timerQueue;
  63.          timerQueue = var0;
  64.          notified = true;
  65.          timerThread.notify();
  66.       }
  67.  
  68.       if (debug) {
  69.          long var3 = System.currentTimeMillis();
  70.          System.out.print(Thread.currentThread().getName() + ": enqueue " + var0.interval + ": ");
  71.  
  72.          for(Timer var8 = timerQueue; var8 != null; var8 = var8.next) {
  73.             long var5 = var8.sleepUntil - var3;
  74.             System.out.print(var8.interval + "(" + var5 + ") ");
  75.          }
  76.  
  77.          System.out.println();
  78.       }
  79.  
  80.    }
  81.  
  82.    protected static boolean dequeue(Timer var0) {
  83.       Timer var1 = null;
  84.  
  85.       Timer var2;
  86.       for(var2 = timerQueue; var2 != null && var2 != var0; var2 = var2.next) {
  87.          var1 = var2;
  88.       }
  89.  
  90.       if (var2 == null) {
  91.          if (debug) {
  92.             System.out.println(Thread.currentThread().getName() + ": dequeue " + var0.interval + ": no-op");
  93.          }
  94.  
  95.          return false;
  96.       } else {
  97.          if (var1 == null) {
  98.             timerQueue = var0.next;
  99.             notified = true;
  100.             timerThread.notify();
  101.          } else {
  102.             var1.next = var0.next;
  103.          }
  104.  
  105.          var0.next = null;
  106.          if (debug) {
  107.             long var3 = System.currentTimeMillis();
  108.             System.out.print(Thread.currentThread().getName() + ": dequeue " + var0.interval + ": ");
  109.  
  110.             for(Timer var7 = timerQueue; var7 != null; var7 = var7.next) {
  111.                long var5 = var7.sleepUntil - var3;
  112.                System.out.print(var7.interval + "(" + var5 + ") ");
  113.             }
  114.  
  115.             System.out.println();
  116.          }
  117.  
  118.          return true;
  119.       }
  120.    }
  121.  
  122.    protected static void requeue(Timer var0) {
  123.       if (!var0.stopped) {
  124.          long var1 = System.currentTimeMillis();
  125.          if (var0.regular) {
  126.             var0.sleepUntil += var0.interval;
  127.          } else {
  128.             var0.sleepUntil = var1 + var0.interval;
  129.          }
  130.  
  131.          enqueue(var0);
  132.       } else {
  133.          if (debug) {
  134.             System.out.println(Thread.currentThread().getName() + ": requeue " + var0.interval + ": no-op");
  135.          }
  136.  
  137.       }
  138.    }
  139. }
  140.