home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1998 January / PCO0198.ISO / 1&1 / java.z / java_301 / sun / awt / ScreenUpdater.class (.txt) next >
Encoding:
Java Class File  |  1996-10-20  |  3.4 KB  |  115 lines

  1. package sun.awt;
  2.  
  3. public class ScreenUpdater extends Thread {
  4.    private final int PRIORITY = 4;
  5.    private ScreenUpdaterEntry first;
  6.    public static final ScreenUpdater updater = newScreenUpdater();
  7.  
  8.    static ThreadGroup findSystemThreadGroup() {
  9.       Thread thread = Thread.currentThread();
  10.  
  11.       ThreadGroup group;
  12.       for(group = thread.getThreadGroup(); group != null && !group.getName().equals("main"); group = group.getParent()) {
  13.       }
  14.  
  15.       return group;
  16.    }
  17.  
  18.    static ScreenUpdater newScreenUpdater() {
  19.       SecurityManager.setScopePermission();
  20.       return new ScreenUpdater(findSystemThreadGroup(), "ScreenUpdater");
  21.    }
  22.  
  23.    private ScreenUpdater(ThreadGroup group, String name) {
  24.       super(group, name);
  25.       ((Thread)this).start();
  26.    }
  27.  
  28.    private ScreenUpdater() {
  29.       ((Thread)this).start();
  30.    }
  31.  
  32.    private synchronized ScreenUpdaterEntry nextEntry() throws InterruptedException {
  33.       while(true) {
  34.          if (this.first == null) {
  35.             ScreenUpdaterEntry entry = null;
  36.             this.wait();
  37.          } else {
  38.             long delay = this.first.when - System.currentTimeMillis();
  39.             if (delay <= 0L) {
  40.                ScreenUpdaterEntry entry = this.first;
  41.                this.first = this.first.next;
  42.                return entry;
  43.             }
  44.  
  45.             ScreenUpdaterEntry entry = null;
  46.             this.wait(delay);
  47.          }
  48.       }
  49.    }
  50.  
  51.    public void run() {
  52.       SecurityManager.setScopePermission();
  53.       ((Thread)this).setName("ScreenUpdater");
  54.  
  55.       try {
  56.          while(true) {
  57.             ((Thread)this).setPriority(4);
  58.             ScreenUpdaterEntry entry = this.nextEntry();
  59.             ((Thread)this).setPriority(entry.client.updatePriority());
  60.  
  61.             try {
  62.                entry.client.updateClient(entry.arg);
  63.             } catch (Throwable e) {
  64.                e.printStackTrace();
  65.             }
  66.  
  67.             ScreenUpdaterEntry var5 = null;
  68.          }
  69.       } catch (InterruptedException var4) {
  70.       }
  71.    }
  72.  
  73.    public void notify(UpdateClient client) {
  74.       this.notify(client, 100L, (Object)null);
  75.    }
  76.  
  77.    public synchronized void notify(UpdateClient client, long delay) {
  78.       this.notify(client, delay, (Object)null);
  79.    }
  80.  
  81.    public synchronized void notify(UpdateClient client, long delay, Object arg) {
  82.       long when = System.currentTimeMillis() + delay;
  83.       long nextwhen = this.first != null ? this.first.when : -1L;
  84.       if (this.first != null) {
  85.          if (this.first.client == client) {
  86.             when = Math.min(this.first.when, when);
  87.             this.first = this.first.next;
  88.          } else {
  89.             for(ScreenUpdaterEntry e = this.first; e.next != null; e = e.next) {
  90.                if (e.next.client == client && e.next.arg == arg) {
  91.                   when = Math.min(e.next.when, when);
  92.                   e.next = e.next.next;
  93.                   break;
  94.                }
  95.             }
  96.          }
  97.       }
  98.  
  99.       if (this.first != null && this.first.when <= when) {
  100.          ScreenUpdaterEntry e;
  101.          for(e = this.first; e.next != null && e.next.when <= when; e = e.next) {
  102.          }
  103.  
  104.          e.next = new ScreenUpdaterEntry(client, when, arg, e.next);
  105.       } else {
  106.          this.first = new ScreenUpdaterEntry(client, when, arg, this.first);
  107.       }
  108.  
  109.       if (nextwhen != this.first.when) {
  110.          super.notify();
  111.       }
  112.  
  113.    }
  114. }
  115.