1 Clazz.declarePackage ("java.lang");
2 Clazz.load (["java.lang.Thread"], "java.lang.ThreadGroup", ["java.lang.IllegalThreadStateException", "$.ThreadDeath", "java.util.Arrays"], function () {
3 c$ = Clazz.decorateAsClass (function () {
7 this.destroyed = false;
9 this.vmAllowSuspension = false;
10 this.nUnstartedThreads = 0;
15 this.html5Applet = null;
16 Clazz.instantialize (this, arguments);
17 }, java.lang, "ThreadGroup", null, java.lang.Thread.UncaughtExceptionHandler);
18 Clazz.makeConstructor (c$,
20 this.construct (java.lang.Thread.currentThread ().getThreadGroup (), name);
22 Clazz.makeConstructor (c$,
23 function (parent, name) {
27 this.maxPriority = parent.maxPriority;
28 this.daemon = parent.daemon;
29 this.vmAllowSuspension = parent.vmAllowSuspension;
31 }}, "java.lang.ThreadGroup,~S");
32 Clazz.defineMethod (c$, "getName",
36 Clazz.defineMethod (c$, "getParent",
38 if (this.parent != null) this.parent.checkAccess ();
41 Clazz.defineMethod (c$, "getMaxPriority",
43 return this.maxPriority;
45 Clazz.defineMethod (c$, "isDaemon",
49 Clazz.defineMethod (c$, "isDestroyed",
51 return this.destroyed;
53 Clazz.defineMethod (c$, "setDaemon",
58 Clazz.defineMethod (c$, "setMaxPriority",
64 if (pri < 1 || pri > 10) {
66 }this.maxPriority = (this.parent != null) ? Math.min (pri, this.parent.maxPriority) : pri;
67 ngroupsSnapshot = this.ngroups;
68 if (this.groups != null) {
69 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
71 groupsSnapshot = null;
72 }}for (var i = 0; i < ngroupsSnapshot; i++) {
73 groupsSnapshot[i].setMaxPriority (pri);
76 Clazz.defineMethod (c$, "parentOf",
78 for (; g != null; g = g.parent) {
83 }, "java.lang.ThreadGroup");
84 Clazz.defineMethod (c$, "checkAccess",
87 Clazz.defineMethod (c$, "activeCount",
95 }result = this.nthreads;
96 ngroupsSnapshot = this.ngroups;
97 if (this.groups != null) {
98 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
100 groupsSnapshot = null;
101 }}for (var i = 0; i < ngroupsSnapshot; i++) {
102 result += groupsSnapshot[i].activeCount ();
106 Clazz.defineMethod (c$, "enumerate",
109 return this.enumerate (list, 0, true);
111 Clazz.defineMethod (c$, "enumerate",
112 function (list, recurse) {
114 return this.enumerate (list, 0, recurse);
116 Clazz.defineMethod (c$, "enumerate",
117 function (list, n, recurse) {
118 var ngroupsSnapshot = 0;
119 var groupsSnapshot = null;
121 if (this.destroyed) {
123 }var nt = this.nthreads;
124 if (nt > list.length - n) {
125 nt = list.length - n;
126 }for (var i = 0; i < nt; i++) {
127 if (this.threads[i].isAlive ()) {
128 list[n++] = this.threads[i];
131 ngroupsSnapshot = this.ngroups;
132 if (this.groups != null) {
133 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
135 groupsSnapshot = null;
137 for (var i = 0; i < ngroupsSnapshot; i++) {
138 n = groupsSnapshot[i].enumerate (list, n, true);
142 Clazz.defineMethod (c$, "activeGroupCount",
147 if (this.destroyed) {
149 }ngroupsSnapshot = this.ngroups;
150 if (this.groups != null) {
151 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
153 groupsSnapshot = null;
154 }}var n = ngroupsSnapshot;
155 for (var i = 0; i < ngroupsSnapshot; i++) {
156 n += groupsSnapshot[i].activeGroupCount ();
160 Clazz.defineMethod (c$, "enumerate",
163 return this.enumerate (list, 0, true);
165 Clazz.defineMethod (c$, "enumerate",
166 function (list, recurse) {
168 return this.enumerate (list, 0, recurse);
170 Clazz.defineMethod (c$, "enumerate",
171 function (list, n, recurse) {
172 var ngroupsSnapshot = 0;
173 var groupsSnapshot = null;
175 if (this.destroyed) {
177 }var ng = this.ngroups;
178 if (ng > list.length - n) {
179 ng = list.length - n;
181 System.arraycopy (this.groups, 0, list, n, ng);
184 ngroupsSnapshot = this.ngroups;
185 if (this.groups != null) {
186 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
188 groupsSnapshot = null;
190 for (var i = 0; i < ngroupsSnapshot; i++) {
191 n = groupsSnapshot[i].enumerate (list, n, true);
195 Clazz.defineMethod (c$, "stop",
197 if (this.stopOrSuspend (false)) java.lang.Thread.currentThread ().stop ();
199 Clazz.defineMethod (c$, "interrupt",
205 for (var i = 0; i < this.nthreads; i++) {
206 this.threads[i].interrupt ();
208 ngroupsSnapshot = this.ngroups;
209 if (this.groups != null) {
210 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
212 groupsSnapshot = null;
213 }}for (var i = 0; i < ngroupsSnapshot; i++) {
214 groupsSnapshot[i].interrupt ();
217 Clazz.defineMethod (c$, "suspend",
219 if (this.stopOrSuspend (true)) java.lang.Thread.currentThread ().suspend ();
221 Clazz.defineMethod (c$, "stopOrSuspend",
224 var us = java.lang.Thread.currentThread ();
226 var groupsSnapshot = null;
229 for (var i = 0; i < this.nthreads; i++) {
230 if (this.threads[i] === us) suicide = true;
231 else if (suspend) this.threads[i].suspend ();
232 else this.threads[i].stop ();
234 ngroupsSnapshot = this.ngroups;
235 if (this.groups != null) {
236 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
237 }}for (var i = 0; i < ngroupsSnapshot; i++) suicide = groupsSnapshot[i].stopOrSuspend (suspend) || suicide;
241 Clazz.defineMethod (c$, "resume",
247 for (var i = 0; i < this.nthreads; i++) {
248 this.threads[i].resume ();
250 ngroupsSnapshot = this.ngroups;
251 if (this.groups != null) {
252 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
254 groupsSnapshot = null;
255 }}for (var i = 0; i < ngroupsSnapshot; i++) {
256 groupsSnapshot[i].resume ();
259 Clazz.defineMethod (c$, "destroy",
265 if (this.destroyed || (this.nthreads > 0)) {
266 throw new IllegalThreadStateException ();
267 }ngroupsSnapshot = this.ngroups;
268 if (this.groups != null) {
269 groupsSnapshot = java.util.Arrays.copyOf (this.groups, ngroupsSnapshot);
271 groupsSnapshot = null;
272 }if (this.parent != null) {
273 this.destroyed = true;
278 }}for (var i = 0; i < ngroupsSnapshot; i += 1) {
279 groupsSnapshot[i].destroy ();
281 if (this.parent != null) {
282 this.parent.remove (this);
284 Clazz.defineMethod (c$, "add",
287 if (this.destroyed) {
288 throw new IllegalThreadStateException ();
289 }if (this.groups == null) {
290 this.groups = new Array (4);
291 } else if (this.ngroups == this.groups.length) {
292 this.groups = java.util.Arrays.copyOf (this.groups, this.ngroups * 2);
293 }this.groups[this.ngroups] = g;
295 }}, "java.lang.ThreadGroup");
296 Clazz.defineMethod (c$, "remove",
299 if (this.destroyed) {
301 }for (var i = 0; i < this.ngroups; i++) {
302 if (this.groups[i] === g) {
304 System.arraycopy (this.groups, i + 1, this.groups, i, this.ngroups - i);
305 this.groups[this.ngroups] = null;
308 if (this.nthreads == 0) {
310 }if (this.daemon && (this.nthreads == 0) && (this.nUnstartedThreads == 0) && (this.ngroups == 0)) {
312 }}}, "java.lang.ThreadGroup");
313 Clazz.defineMethod (c$, "addUnstarted",
316 if (this.destroyed) {
317 throw new IllegalThreadStateException ();
318 }this.nUnstartedThreads++;
320 Clazz.defineMethod (c$, "add",
323 if (this.destroyed) {
324 throw new IllegalThreadStateException ();
325 }if (this.threads == null) {
326 this.threads = new Array (4);
327 } else if (this.nthreads == this.threads.length) {
328 this.threads = java.util.Arrays.copyOf (this.threads, this.nthreads * 2);
329 }this.threads[this.nthreads] = t;
331 this.nUnstartedThreads--;
332 }}, "java.lang.Thread");
333 Clazz.defineMethod (c$, "remove",
336 if (this.destroyed) {
338 }for (var i = 0; i < this.nthreads; i++) {
339 if (this.threads[i] === t) {
340 System.arraycopy (this.threads, i + 1, this.threads, i, --this.nthreads - i);
341 this.threads[this.nthreads] = null;
344 if (this.nthreads == 0) {
346 }if (this.daemon && (this.nthreads == 0) && (this.nUnstartedThreads == 0) && (this.ngroups == 0)) {
348 }}}, "java.lang.Thread");
349 Clazz.defineMethod (c$, "uncaughtException",
351 if (this.parent != null) {
352 this.parent.uncaughtException (t, e);
354 var ueh = java.lang.Thread.getDefaultUncaughtExceptionHandler ();
356 ueh.uncaughtException (t, e);
357 } else if (!(Clazz.instanceOf (e, ThreadDeath))) {
358 System.err.print ("Exception in thread \"" + t.getName () + "\" ");
359 e.printStackTrace (System.err);
360 }}}, "java.lang.Thread,Throwable");
361 Clazz.overrideMethod (c$, "toString",
363 return this.getClass ().getName () + "[name=" + this.getName () + ",maxpri=" + this.maxPriority + ",html5Applet=" + this.html5Applet + "]";