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