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

  1. package java.lang;
  2.  
  3. import java.io.PrintStream;
  4. import sun.misc.VM;
  5.  
  6. public class ThreadGroup {
  7.    ThreadGroup parent;
  8.    String name;
  9.    int maxPriority;
  10.    boolean destroyed;
  11.    boolean daemon;
  12.    boolean vmAllowSuspension;
  13.    int nthreads;
  14.    Thread[] threads;
  15.    int ngroups;
  16.    ThreadGroup[] groups;
  17.  
  18.    private ThreadGroup() {
  19.       this.name = "system";
  20.       this.maxPriority = 10;
  21.    }
  22.  
  23.    public ThreadGroup(String var1) {
  24.       this(Thread.currentThread().getThreadGroup(), var1);
  25.    }
  26.  
  27.    public ThreadGroup(ThreadGroup var1, String var2) {
  28.       if (var1 == null) {
  29.          throw new NullPointerException();
  30.       } else {
  31.          var1.checkAccess();
  32.          this.name = var2;
  33.          this.maxPriority = var1.maxPriority;
  34.          this.daemon = var1.daemon;
  35.          this.vmAllowSuspension = var1.vmAllowSuspension;
  36.          this.parent = var1;
  37.          var1.add(this);
  38.       }
  39.    }
  40.  
  41.    public final String getName() {
  42.       return this.name;
  43.    }
  44.  
  45.    public final ThreadGroup getParent() {
  46.       this.checkAccess();
  47.       return this.parent;
  48.    }
  49.  
  50.    public final int getMaxPriority() {
  51.       return this.maxPriority;
  52.    }
  53.  
  54.    public final boolean isDaemon() {
  55.       return this.daemon;
  56.    }
  57.  
  58.    public synchronized boolean isDestroyed() {
  59.       return this.destroyed;
  60.    }
  61.  
  62.    public final void setDaemon(boolean var1) {
  63.       this.checkAccess();
  64.       this.daemon = var1;
  65.    }
  66.  
  67.    public final void setMaxPriority(int var1) {
  68.       synchronized(this){}
  69.  
  70.       int var2;
  71.       ThreadGroup[] var3;
  72.       try {
  73.          this.checkAccess();
  74.          if (var1 < 1) {
  75.             this.maxPriority = 1;
  76.          } else if (var1 < this.maxPriority) {
  77.             this.maxPriority = var1;
  78.          }
  79.  
  80.          var2 = this.ngroups;
  81.          if (this.groups != null) {
  82.             var3 = new ThreadGroup[var2];
  83.             System.arraycopy(this.groups, 0, var3, 0, var2);
  84.          } else {
  85.             var3 = null;
  86.          }
  87.       } catch (Throwable var6) {
  88.          throw var6;
  89.       }
  90.  
  91.       for(int var4 = 0; var4 < var2; ++var4) {
  92.          var3[var4].setMaxPriority(var1);
  93.       }
  94.  
  95.    }
  96.  
  97.    public final boolean parentOf(ThreadGroup var1) {
  98.       while(var1 != null) {
  99.          if (var1 == this) {
  100.             return true;
  101.          }
  102.  
  103.          var1 = var1.parent;
  104.       }
  105.  
  106.       return false;
  107.    }
  108.  
  109.    public final void checkAccess() {
  110.       SecurityManager var1 = System.getSecurityManager();
  111.       if (var1 != null) {
  112.          var1.checkAccess(this);
  113.       }
  114.  
  115.    }
  116.  
  117.    public int activeCount() {
  118.       synchronized(this){}
  119.  
  120.       int var1;
  121.       int var2;
  122.       ThreadGroup[] var3;
  123.       try {
  124.          if (this.destroyed) {
  125.             byte var9 = 0;
  126.             return var9;
  127.          }
  128.  
  129.          var1 = this.nthreads;
  130.          var2 = this.ngroups;
  131.          if (this.groups != null) {
  132.             var3 = new ThreadGroup[var2];
  133.             System.arraycopy(this.groups, 0, var3, 0, var2);
  134.          } else {
  135.             var3 = null;
  136.          }
  137.       } catch (Throwable var8) {
  138.          throw var8;
  139.       }
  140.  
  141.       for(int var4 = 0; var4 < var2; ++var4) {
  142.          var1 += var3[var4].activeCount();
  143.       }
  144.  
  145.       return var1;
  146.    }
  147.  
  148.    public int enumerate(Thread[] var1) {
  149.       return this.enumerate((Thread[])var1, 0, true);
  150.    }
  151.  
  152.    public int enumerate(Thread[] var1, boolean var2) {
  153.       return this.enumerate((Thread[])var1, 0, var2);
  154.    }
  155.  
  156.    private int enumerate(Thread[] var1, int var2, boolean var3) {
  157.       int var4 = 0;
  158.       ThreadGroup[] var5 = null;
  159.       synchronized(this){}
  160.  
  161.       try {
  162.          if (this.destroyed) {
  163.             byte var12 = 0;
  164.             return var12;
  165.          }
  166.  
  167.          int var9 = this.nthreads;
  168.          if (var9 > var1.length - var2) {
  169.             var9 = var1.length - var2;
  170.          }
  171.  
  172.          if (var9 > 0) {
  173.             System.arraycopy(this.threads, 0, var1, var2, var9);
  174.             var2 += var9;
  175.          }
  176.  
  177.          if (var3) {
  178.             var4 = this.ngroups;
  179.             if (this.groups != null) {
  180.                var5 = new ThreadGroup[var4];
  181.                System.arraycopy(this.groups, 0, var5, 0, var4);
  182.             } else {
  183.                var5 = null;
  184.             }
  185.          }
  186.       } catch (Throwable var11) {
  187.          throw var11;
  188.       }
  189.  
  190.       if (var3) {
  191.          for(int var6 = 0; var6 < var4; ++var6) {
  192.             var2 = var5[var6].enumerate(var1, var2, true);
  193.          }
  194.       }
  195.  
  196.       return var2;
  197.    }
  198.  
  199.    public int activeGroupCount() {
  200.       synchronized(this){}
  201.  
  202.       int var1;
  203.       ThreadGroup[] var2;
  204.       try {
  205.          if (this.destroyed) {
  206.             byte var8 = 0;
  207.             return var8;
  208.          }
  209.  
  210.          var1 = this.ngroups;
  211.          if (this.groups != null) {
  212.             var2 = new ThreadGroup[var1];
  213.             System.arraycopy(this.groups, 0, var2, 0, var1);
  214.          } else {
  215.             var2 = null;
  216.          }
  217.       } catch (Throwable var7) {
  218.          throw var7;
  219.       }
  220.  
  221.       int var3 = var1;
  222.  
  223.       for(int var4 = 0; var4 < var1; ++var4) {
  224.          var3 += var2[var4].activeGroupCount();
  225.       }
  226.  
  227.       return var3;
  228.    }
  229.  
  230.    public int enumerate(ThreadGroup[] var1) {
  231.       return this.enumerate((ThreadGroup[])var1, 0, true);
  232.    }
  233.  
  234.    public int enumerate(ThreadGroup[] var1, boolean var2) {
  235.       return this.enumerate((ThreadGroup[])var1, 0, var2);
  236.    }
  237.  
  238.    private int enumerate(ThreadGroup[] var1, int var2, boolean var3) {
  239.       int var4 = 0;
  240.       ThreadGroup[] var5 = null;
  241.       synchronized(this){}
  242.  
  243.       try {
  244.          if (this.destroyed) {
  245.             byte var12 = 0;
  246.             return var12;
  247.          }
  248.  
  249.          int var9 = this.ngroups;
  250.          if (var9 > var1.length - var2) {
  251.             var9 = var1.length - var2;
  252.          }
  253.  
  254.          if (var9 > 0) {
  255.             System.arraycopy(this.groups, 0, var1, var2, var9);
  256.             var2 += var9;
  257.          }
  258.  
  259.          if (var3) {
  260.             var4 = this.ngroups;
  261.             if (this.groups != null) {
  262.                var5 = new ThreadGroup[var4];
  263.                System.arraycopy(this.groups, 0, var5, 0, var4);
  264.             } else {
  265.                var5 = null;
  266.             }
  267.          }
  268.       } catch (Throwable var11) {
  269.          throw var11;
  270.       }
  271.  
  272.       if (var3) {
  273.          for(int var6 = 0; var6 < var4; ++var6) {
  274.             var2 = var5[var6].enumerate(var1, var2, true);
  275.          }
  276.       }
  277.  
  278.       return var2;
  279.    }
  280.  
  281.    public final void stop() {
  282.       synchronized(this){}
  283.  
  284.       int var1;
  285.       ThreadGroup[] var2;
  286.       try {
  287.          this.checkAccess();
  288.  
  289.          for(int var5 = 0; var5 < this.nthreads; ++var5) {
  290.             this.threads[var5].stop();
  291.          }
  292.  
  293.          var1 = this.ngroups;
  294.          if (this.groups != null) {
  295.             var2 = new ThreadGroup[var1];
  296.             System.arraycopy(this.groups, 0, var2, 0, var1);
  297.          } else {
  298.             var2 = null;
  299.          }
  300.       } catch (Throwable var7) {
  301.          throw var7;
  302.       }
  303.  
  304.       for(int var3 = 0; var3 < var1; ++var3) {
  305.          var2[var3].stop();
  306.       }
  307.  
  308.    }
  309.  
  310.    public final void suspend() {
  311.       synchronized(this){}
  312.  
  313.       int var1;
  314.       ThreadGroup[] var2;
  315.       try {
  316.          this.checkAccess();
  317.  
  318.          for(int var5 = 0; var5 < this.nthreads; ++var5) {
  319.             this.threads[var5].suspend();
  320.          }
  321.  
  322.          var1 = this.ngroups;
  323.          if (this.groups != null) {
  324.             var2 = new ThreadGroup[var1];
  325.             System.arraycopy(this.groups, 0, var2, 0, var1);
  326.          } else {
  327.             var2 = null;
  328.          }
  329.       } catch (Throwable var7) {
  330.          throw var7;
  331.       }
  332.  
  333.       for(int var3 = 0; var3 < var1; ++var3) {
  334.          var2[var3].suspend();
  335.       }
  336.  
  337.    }
  338.  
  339.    public final void resume() {
  340.       synchronized(this){}
  341.  
  342.       int var1;
  343.       ThreadGroup[] var2;
  344.       try {
  345.          this.checkAccess();
  346.  
  347.          for(int var5 = 0; var5 < this.nthreads; ++var5) {
  348.             this.threads[var5].resume();
  349.          }
  350.  
  351.          var1 = this.ngroups;
  352.          if (this.groups != null) {
  353.             var2 = new ThreadGroup[var1];
  354.             System.arraycopy(this.groups, 0, var2, 0, var1);
  355.          } else {
  356.             var2 = null;
  357.          }
  358.       } catch (Throwable var7) {
  359.          throw var7;
  360.       }
  361.  
  362.       for(int var3 = 0; var3 < var1; ++var3) {
  363.          var2[var3].resume();
  364.       }
  365.  
  366.    }
  367.  
  368.    public final void destroy() {
  369.       synchronized(this){}
  370.  
  371.       int var1;
  372.       ThreadGroup[] var2;
  373.       try {
  374.          this.checkAccess();
  375.          if (this.destroyed || this.nthreads > 0) {
  376.             throw new IllegalThreadStateException();
  377.          }
  378.  
  379.          var1 = this.ngroups;
  380.          if (this.groups != null) {
  381.             var2 = new ThreadGroup[var1];
  382.             System.arraycopy(this.groups, 0, var2, 0, var1);
  383.          } else {
  384.             var2 = null;
  385.          }
  386.  
  387.          if (this.parent != null) {
  388.             this.destroyed = true;
  389.             this.ngroups = 0;
  390.             this.groups = null;
  391.             this.nthreads = 0;
  392.             this.threads = null;
  393.          }
  394.       } catch (Throwable var5) {
  395.          throw var5;
  396.       }
  397.  
  398.       for(int var3 = 0; var3 < var1; ++var3) {
  399.          var2[var3].destroy();
  400.       }
  401.  
  402.       if (this.parent != null) {
  403.          this.parent.remove(this);
  404.       }
  405.  
  406.    }
  407.  
  408.    private final void add(ThreadGroup var1) {
  409.       synchronized(this){}
  410.  
  411.       try {
  412.          if (this.destroyed) {
  413.             throw new IllegalThreadStateException();
  414.          }
  415.  
  416.          if (this.groups == null) {
  417.             this.groups = new ThreadGroup[4];
  418.          } else if (this.ngroups == this.groups.length) {
  419.             ThreadGroup[] var4 = new ThreadGroup[this.ngroups * 2];
  420.             System.arraycopy(this.groups, 0, var4, 0, this.ngroups);
  421.             this.groups = var4;
  422.          }
  423.  
  424.          this.groups[this.ngroups] = var1;
  425.          ++this.ngroups;
  426.       } catch (Throwable var6) {
  427.          throw var6;
  428.       }
  429.  
  430.    }
  431.  
  432.    private void remove(ThreadGroup var1) {
  433.       synchronized(this){}
  434.  
  435.       try {
  436.          if (!this.destroyed) {
  437.             for(int var4 = 0; var4 < this.ngroups; ++var4) {
  438.                if (this.groups[var4] == var1) {
  439.                   --this.ngroups;
  440.                   System.arraycopy(this.groups, var4 + 1, this.groups, var4, this.ngroups - var4);
  441.                   this.groups[this.ngroups] = null;
  442.                   break;
  443.                }
  444.             }
  445.  
  446.             if (this.nthreads == 0) {
  447.                this.notifyAll();
  448.             }
  449.  
  450.             if (this.daemon && this.nthreads == 0 && this.ngroups == 0) {
  451.                this.destroy();
  452.             }
  453.  
  454.             return;
  455.          }
  456.       } catch (Throwable var6) {
  457.          throw var6;
  458.       }
  459.  
  460.    }
  461.  
  462.    void add(Thread var1) {
  463.       synchronized(this){}
  464.  
  465.       try {
  466.          if (this.destroyed) {
  467.             throw new IllegalThreadStateException();
  468.          }
  469.  
  470.          if (this.threads == null) {
  471.             this.threads = new Thread[4];
  472.          } else if (this.nthreads == this.threads.length) {
  473.             Thread[] var4 = new Thread[this.nthreads * 2];
  474.             System.arraycopy(this.threads, 0, var4, 0, this.nthreads);
  475.             this.threads = var4;
  476.          }
  477.  
  478.          this.threads[this.nthreads] = var1;
  479.          ++this.nthreads;
  480.       } catch (Throwable var6) {
  481.          throw var6;
  482.       }
  483.  
  484.    }
  485.  
  486.    void remove(Thread var1) {
  487.       synchronized(this){}
  488.  
  489.       try {
  490.          if (!this.destroyed) {
  491.             for(int var4 = 0; var4 < this.nthreads; ++var4) {
  492.                if (this.threads[var4] == var1) {
  493.                   System.arraycopy(this.threads, var4 + 1, this.threads, var4, --this.nthreads - var4);
  494.                   this.threads[this.nthreads] = null;
  495.                   break;
  496.                }
  497.             }
  498.  
  499.             if (this.nthreads == 0) {
  500.                this.notifyAll();
  501.             }
  502.  
  503.             if (this.daemon && this.nthreads == 0 && this.ngroups == 0) {
  504.                this.destroy();
  505.             }
  506.  
  507.             return;
  508.          }
  509.       } catch (Throwable var6) {
  510.          throw var6;
  511.       }
  512.  
  513.    }
  514.  
  515.    public void list() {
  516.       this.list(System.out, 0);
  517.    }
  518.  
  519.    void list(PrintStream var1, int var2) {
  520.       synchronized(this){}
  521.  
  522.       int var3;
  523.       ThreadGroup[] var4;
  524.       try {
  525.          for(int var7 = 0; var7 < var2; ++var7) {
  526.             var1.print(" ");
  527.          }
  528.  
  529.          var1.println(this);
  530.          var2 += 4;
  531.  
  532.          for(int var8 = 0; var8 < this.nthreads; ++var8) {
  533.             for(int var9 = 0; var9 < var2; ++var9) {
  534.                var1.print(" ");
  535.             }
  536.  
  537.             var1.println(this.threads[var8]);
  538.          }
  539.  
  540.          var3 = this.ngroups;
  541.          if (this.groups != null) {
  542.             var4 = new ThreadGroup[var3];
  543.             System.arraycopy(this.groups, 0, var4, 0, var3);
  544.          } else {
  545.             var4 = null;
  546.          }
  547.       } catch (Throwable var11) {
  548.          throw var11;
  549.       }
  550.  
  551.       for(int var5 = 0; var5 < var3; ++var5) {
  552.          var4[var5].list(var1, var2);
  553.       }
  554.  
  555.    }
  556.  
  557.    public void uncaughtException(Thread var1, Throwable var2) {
  558.       if (this.parent != null) {
  559.          this.parent.uncaughtException(var1, var2);
  560.       } else {
  561.          if (!(var2 instanceof ThreadDeath)) {
  562.             var2.printStackTrace(System.err);
  563.          }
  564.  
  565.       }
  566.    }
  567.  
  568.    public boolean allowThreadSuspension(boolean var1) {
  569.       this.vmAllowSuspension = var1;
  570.       if (!var1) {
  571.          VM.unsuspendSomeThreads();
  572.       }
  573.  
  574.       return true;
  575.    }
  576.  
  577.    public String toString() {
  578.       return this.getClass().getName() + "[name=" + this.getName() + ",maxpri=" + this.maxPriority + "]";
  579.    }
  580. }
  581.