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