home *** CD-ROM | disk | FTP | other *** search
- package java.lang;
-
- import java.io.PrintStream;
- import sun.misc.VM;
-
- public class ThreadGroup {
- ThreadGroup parent;
- String name;
- int maxPriority;
- boolean destroyed;
- boolean daemon;
- boolean vmAllowSuspension;
- int nthreads;
- Thread[] threads;
- int ngroups;
- ThreadGroup[] groups;
-
- private ThreadGroup() {
- this.name = "system";
- this.maxPriority = 10;
- }
-
- public ThreadGroup(String var1) {
- this(Thread.currentThread().getThreadGroup(), var1);
- }
-
- public ThreadGroup(ThreadGroup var1, String var2) {
- if (var1 == null) {
- throw new NullPointerException();
- } else {
- var1.checkAccess();
- this.name = var2;
- this.maxPriority = var1.maxPriority;
- this.daemon = var1.daemon;
- this.vmAllowSuspension = var1.vmAllowSuspension;
- this.parent = var1;
- var1.add(this);
- }
- }
-
- public final String getName() {
- return this.name;
- }
-
- public final ThreadGroup getParent() {
- if (this.parent != null) {
- this.parent.checkAccess();
- }
-
- return this.parent;
- }
-
- public final int getMaxPriority() {
- return this.maxPriority;
- }
-
- public final boolean isDaemon() {
- return this.daemon;
- }
-
- public synchronized boolean isDestroyed() {
- return this.destroyed;
- }
-
- public final void setDaemon(boolean var1) {
- this.checkAccess();
- this.daemon = var1;
- }
-
- public final void setMaxPriority(int var1) {
- int var2;
- ThreadGroup[] var3;
- synchronized(this) {
- this.checkAccess();
- if (var1 < 1) {
- this.maxPriority = 1;
- } else if (var1 < this.maxPriority) {
- this.maxPriority = var1;
- }
-
- var2 = this.ngroups;
- if (this.groups != null) {
- var3 = new ThreadGroup[var2];
- System.arraycopy(this.groups, 0, var3, 0, var2);
- } else {
- var3 = null;
- }
- }
-
- for(int var5 = 0; var5 < var2; ++var5) {
- var3[var5].setMaxPriority(var1);
- }
-
- }
-
- public final boolean parentOf(ThreadGroup var1) {
- while(var1 != null) {
- if (var1 == this) {
- return true;
- }
-
- var1 = var1.parent;
- }
-
- return false;
- }
-
- public final void checkAccess() {
- SecurityManager var1 = System.getSecurityManager();
- if (var1 != null) {
- var1.checkAccess(this);
- }
-
- }
-
- public int activeCount() {
- int var1;
- int var2;
- ThreadGroup[] var3;
- synchronized(this) {
- if (this.destroyed) {
- byte var8 = 0;
- return var8;
- }
-
- var1 = this.nthreads;
- var2 = this.ngroups;
- if (this.groups != null) {
- var3 = new ThreadGroup[var2];
- System.arraycopy(this.groups, 0, var3, 0, var2);
- } else {
- var3 = null;
- }
- }
-
- for(int var5 = 0; var5 < var2; ++var5) {
- var1 += var3[var5].activeCount();
- }
-
- return var1;
- }
-
- public int enumerate(Thread[] var1) {
- this.checkAccess();
- return this.enumerate((Thread[])var1, 0, true);
- }
-
- public int enumerate(Thread[] var1, boolean var2) {
- this.checkAccess();
- return this.enumerate((Thread[])var1, 0, var2);
- }
-
- private int enumerate(Thread[] var1, int var2, boolean var3) {
- int var4 = 0;
- ThreadGroup[] var5 = null;
- synchronized(this) {
- if (this.destroyed) {
- byte var12 = 0;
- return var12;
- }
-
- int var7 = this.nthreads;
- if (var7 > var1.length - var2) {
- var7 = var1.length - var2;
- }
-
- for(int var8 = 0; var8 < var7; ++var8) {
- if (this.threads[var8].isAlive()) {
- var1[var2++] = this.threads[var8];
- }
- }
-
- if (var3) {
- var4 = this.ngroups;
- if (this.groups != null) {
- var5 = new ThreadGroup[var4];
- System.arraycopy(this.groups, 0, var5, 0, var4);
- } else {
- var5 = null;
- }
- }
- }
-
- if (var3) {
- for(int var11 = 0; var11 < var4; ++var11) {
- var2 = var5[var11].enumerate(var1, var2, true);
- }
- }
-
- return var2;
- }
-
- public int activeGroupCount() {
- int var1;
- ThreadGroup[] var2;
- synchronized(this) {
- if (this.destroyed) {
- byte var7 = 0;
- return var7;
- }
-
- var1 = this.ngroups;
- if (this.groups != null) {
- var2 = new ThreadGroup[var1];
- System.arraycopy(this.groups, 0, var2, 0, var1);
- } else {
- var2 = null;
- }
- }
-
- int var4 = var1;
-
- for(int var5 = 0; var5 < var1; ++var5) {
- var4 += var2[var5].activeGroupCount();
- }
-
- return var4;
- }
-
- public int enumerate(ThreadGroup[] var1) {
- this.checkAccess();
- return this.enumerate((ThreadGroup[])var1, 0, true);
- }
-
- public int enumerate(ThreadGroup[] var1, boolean var2) {
- this.checkAccess();
- return this.enumerate((ThreadGroup[])var1, 0, var2);
- }
-
- private int enumerate(ThreadGroup[] var1, int var2, boolean var3) {
- int var4 = 0;
- ThreadGroup[] var5 = null;
- synchronized(this) {
- if (this.destroyed) {
- byte var11 = 0;
- return var11;
- }
-
- int var7 = this.ngroups;
- if (var7 > var1.length - var2) {
- var7 = var1.length - var2;
- }
-
- if (var7 > 0) {
- System.arraycopy(this.groups, 0, var1, var2, var7);
- var2 += var7;
- }
-
- if (var3) {
- var4 = this.ngroups;
- if (this.groups != null) {
- var5 = new ThreadGroup[var4];
- System.arraycopy(this.groups, 0, var5, 0, var4);
- } else {
- var5 = null;
- }
- }
- }
-
- if (var3) {
- for(int var10 = 0; var10 < var4; ++var10) {
- var2 = var5[var10].enumerate(var1, var2, true);
- }
- }
-
- return var2;
- }
-
- public final void stop() {
- if (this.stopOrSuspend(false)) {
- Thread.currentThread().stop();
- }
-
- }
-
- public final void interrupt() {
- int var1;
- ThreadGroup[] var2;
- synchronized(this) {
- this.checkAccess();
-
- for(int var4 = 0; var4 < this.nthreads; ++var4) {
- this.threads[var4].interrupt();
- }
-
- var1 = this.ngroups;
- if (this.groups != null) {
- var2 = new ThreadGroup[var1];
- System.arraycopy(this.groups, 0, var2, 0, var1);
- } else {
- var2 = null;
- }
- }
-
- for(int var7 = 0; var7 < var1; ++var7) {
- var2[var7].interrupt();
- }
-
- }
-
- public final void suspend() {
- if (this.stopOrSuspend(true)) {
- Thread.currentThread().suspend();
- }
-
- }
-
- private boolean stopOrSuspend(boolean var1) {
- boolean var2 = false;
- Thread var3 = Thread.currentThread();
- ThreadGroup[] var5 = null;
- int var4;
- synchronized(this) {
- this.checkAccess();
-
- for(int var7 = 0; var7 < this.nthreads; ++var7) {
- if (this.threads[var7] == var3) {
- var2 = true;
- } else if (var1) {
- this.threads[var7].suspend();
- } else {
- this.threads[var7].stop();
- }
- }
-
- var4 = this.ngroups;
- if (this.groups != null) {
- var5 = new ThreadGroup[var4];
- System.arraycopy(this.groups, 0, var5, 0, var4);
- }
- }
-
- for(int var10 = 0; var10 < var4; ++var10) {
- var2 = var5[var10].stopOrSuspend(var1) || var2;
- }
-
- return var2;
- }
-
- public final void resume() {
- int var1;
- ThreadGroup[] var2;
- synchronized(this) {
- this.checkAccess();
-
- for(int var4 = 0; var4 < this.nthreads; ++var4) {
- this.threads[var4].resume();
- }
-
- var1 = this.ngroups;
- if (this.groups != null) {
- var2 = new ThreadGroup[var1];
- System.arraycopy(this.groups, 0, var2, 0, var1);
- } else {
- var2 = null;
- }
- }
-
- for(int var7 = 0; var7 < var1; ++var7) {
- var2[var7].resume();
- }
-
- }
-
- public final void destroy() {
- int var1;
- ThreadGroup[] var2;
- synchronized(this) {
- this.checkAccess();
- if (this.destroyed || this.nthreads > 0) {
- throw new IllegalThreadStateException();
- }
-
- var1 = this.ngroups;
- if (this.groups != null) {
- var2 = new ThreadGroup[var1];
- System.arraycopy(this.groups, 0, var2, 0, var1);
- } else {
- var2 = null;
- }
-
- if (this.parent != null) {
- this.destroyed = true;
- this.ngroups = 0;
- this.groups = null;
- this.nthreads = 0;
- this.threads = null;
- }
- }
-
- for(int var4 = 0; var4 < var1; ++var4) {
- var2[var4].destroy();
- }
-
- if (this.parent != null) {
- this.parent.remove(this);
- }
-
- }
-
- private final void add(ThreadGroup var1) {
- synchronized(this) {
- if (this.destroyed) {
- throw new IllegalThreadStateException();
- } else {
- if (this.groups == null) {
- this.groups = new ThreadGroup[4];
- } else if (this.ngroups == this.groups.length) {
- ThreadGroup[] var3 = new ThreadGroup[this.ngroups * 2];
- System.arraycopy(this.groups, 0, var3, 0, this.ngroups);
- this.groups = var3;
- }
-
- this.groups[this.ngroups] = var1;
- ++this.ngroups;
- }
- }
- }
-
- private void remove(ThreadGroup var1) {
- synchronized(this) {
- if (!this.destroyed) {
- for(int var3 = 0; var3 < this.ngroups; ++var3) {
- if (this.groups[var3] == var1) {
- --this.ngroups;
- System.arraycopy(this.groups, var3 + 1, this.groups, var3, this.ngroups - var3);
- this.groups[this.ngroups] = null;
- break;
- }
- }
-
- if (this.nthreads == 0) {
- this.notifyAll();
- }
-
- if (this.daemon && this.nthreads == 0 && this.ngroups == 0) {
- this.destroy();
- }
-
- }
- }
- }
-
- void add(Thread var1) {
- synchronized(this) {
- if (this.destroyed) {
- throw new IllegalThreadStateException();
- } else {
- if (this.threads == null) {
- this.threads = new Thread[4];
- } else if (this.nthreads == this.threads.length) {
- Thread[] var3 = new Thread[this.nthreads * 2];
- System.arraycopy(this.threads, 0, var3, 0, this.nthreads);
- this.threads = var3;
- }
-
- this.threads[this.nthreads] = var1;
- ++this.nthreads;
- }
- }
- }
-
- void remove(Thread var1) {
- synchronized(this) {
- if (!this.destroyed) {
- for(int var3 = 0; var3 < this.nthreads; ++var3) {
- if (this.threads[var3] == var1) {
- System.arraycopy(this.threads, var3 + 1, this.threads, var3, --this.nthreads - var3);
- this.threads[this.nthreads] = null;
- break;
- }
- }
-
- if (this.nthreads == 0) {
- this.notifyAll();
- }
-
- if (this.daemon && this.nthreads == 0 && this.ngroups == 0) {
- this.destroy();
- }
-
- }
- }
- }
-
- public void list() {
- this.list(System.out, 0);
- }
-
- void list(PrintStream var1, int var2) {
- int var3;
- ThreadGroup[] var4;
- synchronized(this) {
- for(int var6 = 0; var6 < var2; ++var6) {
- var1.print(" ");
- }
-
- var1.println(this);
- var2 += 4;
-
- for(int var7 = 0; var7 < this.nthreads; ++var7) {
- for(int var8 = 0; var8 < var2; ++var8) {
- var1.print(" ");
- }
-
- var1.println(this.threads[var7]);
- }
-
- var3 = this.ngroups;
- if (this.groups != null) {
- var4 = new ThreadGroup[var3];
- System.arraycopy(this.groups, 0, var4, 0, var3);
- } else {
- var4 = null;
- }
- }
-
- for(int var12 = 0; var12 < var3; ++var12) {
- var4[var12].list(var1, var2);
- }
-
- }
-
- public void uncaughtException(Thread var1, Throwable var2) {
- if (this.parent != null) {
- this.parent.uncaughtException(var1, var2);
- } else if (!(var2 instanceof ThreadDeath)) {
- var2.printStackTrace(System.err);
- }
-
- }
-
- public boolean allowThreadSuspension(boolean var1) {
- this.vmAllowSuspension = var1;
- if (!var1) {
- VM.unsuspendSomeThreads();
- }
-
- return true;
- }
-
- public String toString() {
- return this.getClass().getName() + "[name=" + this.getName() + ",maxpri=" + this.maxPriority + "]";
- }
- }
-