home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / java / lang / ThreadGroup.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-27  |  5.4 KB  |  360 lines

  1. package java.lang;
  2.  
  3. import java.io.PrintStream;
  4.  
  5. public class ThreadGroup {
  6.    ThreadGroup parent;
  7.    String name;
  8.    int maxPriority;
  9.    boolean destroyed;
  10.    boolean daemon;
  11.    int nthreads;
  12.    Thread[] threads;
  13.    int ngroups;
  14.    ThreadGroup[] groups;
  15.  
  16.    private ThreadGroup() {
  17.       this.name = "system";
  18.       this.maxPriority = 10;
  19.    }
  20.  
  21.    public ThreadGroup(String var1) {
  22.       this(Thread.currentThread().getThreadGroup(), var1);
  23.    }
  24.  
  25.    public ThreadGroup(ThreadGroup var1, String var2) {
  26.       if (var1 == null) {
  27.          throw new NullPointerException();
  28.       } else {
  29.          var1.checkAccess();
  30.          this.name = var2;
  31.          this.maxPriority = var1.maxPriority;
  32.          this.daemon = var1.daemon;
  33.          this.parent = var1;
  34.          var1.add(this);
  35.       }
  36.    }
  37.  
  38.    public final String getName() {
  39.       return this.name;
  40.    }
  41.  
  42.    public final ThreadGroup getParent() {
  43.       return this.parent;
  44.    }
  45.  
  46.    public final int getMaxPriority() {
  47.       return this.maxPriority;
  48.    }
  49.  
  50.    public final boolean isDaemon() {
  51.       return this.daemon;
  52.    }
  53.  
  54.    public final void setDaemon(boolean var1) {
  55.       this.checkAccess();
  56.       this.daemon = var1;
  57.    }
  58.  
  59.    public final synchronized void setMaxPriority(int var1) {
  60.       this.checkAccess();
  61.       if (var1 < 1) {
  62.          this.maxPriority = 1;
  63.       } else if (var1 < this.maxPriority) {
  64.          this.maxPriority = var1;
  65.       }
  66.  
  67.       for(int var2 = 0; var2 < this.ngroups; ++var2) {
  68.          this.groups[var2].setMaxPriority(var1);
  69.       }
  70.  
  71.    }
  72.  
  73.    public final boolean parentOf(ThreadGroup var1) {
  74.       while(var1 != null) {
  75.          if (var1 == this) {
  76.             return true;
  77.          }
  78.  
  79.          var1 = var1.parent;
  80.       }
  81.  
  82.       return false;
  83.    }
  84.  
  85.    public final void checkAccess() {
  86.       SecurityManager var1 = System.getSecurityManager();
  87.       if (var1 != null) {
  88.          var1.checkAccess(this);
  89.       }
  90.  
  91.    }
  92.  
  93.    public synchronized int activeCount() {
  94.       if (this.destroyed) {
  95.          return 0;
  96.       } else {
  97.          int var1 = this.nthreads;
  98.  
  99.          for(int var2 = 0; var2 < this.ngroups; ++var2) {
  100.             var1 += this.groups[var2].activeCount();
  101.          }
  102.  
  103.          return var1;
  104.       }
  105.    }
  106.  
  107.    public int enumerate(Thread[] var1) {
  108.       return this.enumerate((Thread[])var1, 0, true);
  109.    }
  110.  
  111.    public int enumerate(Thread[] var1, boolean var2) {
  112.       return this.enumerate((Thread[])var1, 0, var2);
  113.    }
  114.  
  115.    private synchronized int enumerate(Thread[] var1, int var2, boolean var3) {
  116.       if (this.destroyed) {
  117.          return 0;
  118.       } else {
  119.          int var4 = this.nthreads;
  120.          if (var4 > var1.length - var2) {
  121.             var4 = var1.length - var2;
  122.          }
  123.  
  124.          if (var4 > 0) {
  125.             System.arraycopy(this.threads, 0, var1, var2, var4);
  126.             var2 += var4;
  127.          }
  128.  
  129.          if (var3) {
  130.             for(int var5 = 0; var5 < this.ngroups; ++var5) {
  131.                var2 = this.groups[var5].enumerate(var1, var2, true);
  132.             }
  133.          }
  134.  
  135.          return var2;
  136.       }
  137.    }
  138.  
  139.    public synchronized int activeGroupCount() {
  140.       if (this.destroyed) {
  141.          return 0;
  142.       } else {
  143.          int var1 = this.ngroups;
  144.  
  145.          for(int var2 = 0; var2 < this.ngroups; ++var2) {
  146.             var1 += this.groups[var2].activeGroupCount();
  147.          }
  148.  
  149.          return var1;
  150.       }
  151.    }
  152.  
  153.    public int enumerate(ThreadGroup[] var1) {
  154.       return this.enumerate((ThreadGroup[])var1, 0, true);
  155.    }
  156.  
  157.    public int enumerate(ThreadGroup[] var1, boolean var2) {
  158.       return this.enumerate((ThreadGroup[])var1, 0, var2);
  159.    }
  160.  
  161.    private synchronized int enumerate(ThreadGroup[] var1, int var2, boolean var3) {
  162.       if (this.destroyed) {
  163.          return 0;
  164.       } else {
  165.          int var4 = this.ngroups;
  166.          if (var4 > var1.length - var2) {
  167.             var4 = var1.length - var2;
  168.          }
  169.  
  170.          if (var4 > 0) {
  171.             System.arraycopy(this.groups, 0, var1, var2, var4);
  172.             var2 += var4;
  173.          }
  174.  
  175.          if (var3) {
  176.             for(int var5 = 0; var5 < this.ngroups; ++var5) {
  177.                var2 = this.groups[var5].enumerate(var1, var2, true);
  178.             }
  179.          }
  180.  
  181.          return var2;
  182.       }
  183.    }
  184.  
  185.    public final synchronized void stop() {
  186.       this.checkAccess();
  187.  
  188.       for(int var1 = 0; var1 < this.ngroups; ++var1) {
  189.          this.groups[var1].stop();
  190.       }
  191.  
  192.       for(int var2 = 0; var2 < this.nthreads; ++var2) {
  193.          this.threads[var2].stop();
  194.       }
  195.  
  196.    }
  197.  
  198.    public final synchronized void suspend() {
  199.       this.checkAccess();
  200.  
  201.       for(int var1 = 0; var1 < this.ngroups; ++var1) {
  202.          this.groups[var1].suspend();
  203.       }
  204.  
  205.       for(int var2 = 0; var2 < this.nthreads; ++var2) {
  206.          this.threads[var2].suspend();
  207.       }
  208.  
  209.    }
  210.  
  211.    public final synchronized void resume() {
  212.       this.checkAccess();
  213.  
  214.       for(int var1 = 0; var1 < this.ngroups; ++var1) {
  215.          this.groups[var1].resume();
  216.       }
  217.  
  218.       for(int var2 = 0; var2 < this.nthreads; ++var2) {
  219.          this.threads[var2].resume();
  220.       }
  221.  
  222.    }
  223.  
  224.    public final synchronized void destroy() {
  225.       this.checkAccess();
  226.       if (!this.destroyed && this.nthreads <= 0) {
  227.          while(this.ngroups > 0) {
  228.             this.groups[0].destroy();
  229.          }
  230.  
  231.          if (this.parent != null) {
  232.             this.destroyed = true;
  233.             this.groups = null;
  234.             this.threads = null;
  235.             this.parent.remove(this);
  236.          }
  237.  
  238.       } else {
  239.          throw new IllegalThreadStateException();
  240.       }
  241.    }
  242.  
  243.    private final synchronized void add(ThreadGroup var1) {
  244.       if (this.destroyed) {
  245.          throw new IllegalThreadStateException();
  246.       } else {
  247.          if (this.groups == null) {
  248.             this.groups = new ThreadGroup[4];
  249.          } else if (this.ngroups == this.groups.length) {
  250.             ThreadGroup[] var2 = new ThreadGroup[this.ngroups * 2];
  251.             System.arraycopy(this.groups, 0, var2, 0, this.ngroups);
  252.             this.groups = var2;
  253.          }
  254.  
  255.          this.groups[this.ngroups] = var1;
  256.          ++this.ngroups;
  257.       }
  258.    }
  259.  
  260.    private synchronized void remove(ThreadGroup var1) {
  261.       if (!this.destroyed) {
  262.          for(int var2 = 0; var2 < this.ngroups; ++var2) {
  263.             if (this.groups[var2] == var1) {
  264.                System.arraycopy(this.groups, var2 + 1, this.groups, var2, --this.ngroups - var2);
  265.                this.groups[this.ngroups] = null;
  266.                break;
  267.             }
  268.          }
  269.  
  270.          if (this.nthreads == 0) {
  271.             this.notifyAll();
  272.          }
  273.  
  274.          if (this.daemon && this.nthreads == 0 && this.ngroups == 0) {
  275.             this.destroy();
  276.          }
  277.  
  278.       }
  279.    }
  280.  
  281.    synchronized void add(Thread var1) {
  282.       if (this.destroyed) {
  283.          throw new IllegalThreadStateException();
  284.       } else {
  285.          if (this.threads == null) {
  286.             this.threads = new Thread[4];
  287.          } else if (this.nthreads == this.threads.length) {
  288.             Thread[] var2 = new Thread[this.nthreads * 2];
  289.             System.arraycopy(this.threads, 0, var2, 0, this.nthreads);
  290.             this.threads = var2;
  291.          }
  292.  
  293.          this.threads[this.nthreads] = var1;
  294.          ++this.nthreads;
  295.       }
  296.    }
  297.  
  298.    synchronized void remove(Thread var1) {
  299.       if (!this.destroyed) {
  300.          for(int var2 = 0; var2 < this.nthreads; ++var2) {
  301.             if (this.threads[var2] == var1) {
  302.                System.arraycopy(this.threads, var2 + 1, this.threads, var2, --this.nthreads - var2);
  303.                this.threads[this.nthreads] = null;
  304.                break;
  305.             }
  306.          }
  307.  
  308.          if (this.nthreads == 0) {
  309.             this.notifyAll();
  310.          }
  311.  
  312.          if (this.daemon && this.nthreads == 0 && this.ngroups == 0) {
  313.             this.destroy();
  314.          }
  315.  
  316.       }
  317.    }
  318.  
  319.    public synchronized void list() {
  320.       this.list(System.out, 0);
  321.    }
  322.  
  323.    void list(PrintStream var1, int var2) {
  324.       for(int var3 = 0; var3 < var2; ++var3) {
  325.          var1.print(" ");
  326.       }
  327.  
  328.       var1.println(this);
  329.       var2 += 4;
  330.  
  331.       for(int var4 = 0; var4 < this.nthreads; ++var4) {
  332.          for(int var5 = 0; var5 < var2; ++var5) {
  333.             var1.print(" ");
  334.          }
  335.  
  336.          var1.println(this.threads[var4]);
  337.       }
  338.  
  339.       for(int var7 = 0; var7 < this.ngroups; ++var7) {
  340.          this.groups[var7].list(var1, var2);
  341.       }
  342.  
  343.    }
  344.  
  345.    public void uncaughtException(Thread var1, Throwable var2) {
  346.       if (this.parent != null) {
  347.          this.parent.uncaughtException(var1, var2);
  348.       } else {
  349.          if (!(var2 instanceof ThreadDeath)) {
  350.             var2.printStackTrace(System.err);
  351.          }
  352.  
  353.       }
  354.    }
  355.  
  356.    public String toString() {
  357.       return this.getClass().getName() + "[name=" + this.getName() + ",maxpri=" + this.maxPriority + "]";
  358.    }
  359. }
  360.