1 Clazz.declarePackage ("java.lang");
\r
2 Clazz.load (["java.lang.Enum"], "java.lang.Thread", ["java.lang.Exception", "$.IllegalArgumentException", "$.IllegalThreadStateException", "$.NoSuchMethodError", "$.NullPointerException", "$.ThreadDeath", "java.util.HashMap", "java.lang.ThreadGroup", "swingjs.JSToolkit"], function () {
\r
3 c$ = Clazz.decorateAsClass (function () {
\r
10 this.threadStatus = 0;
\r
11 this.parkBlocker = null;
\r
12 this.stopBeforeStart = false;
\r
13 this.throwableFromStop = null;
\r
15 this.uncaughtExceptionHandler = null;
\r
16 this.$interrupted = false;
\r
17 this.stopped = false;
\r
18 Clazz.instantialize (this, arguments);
\r
19 }, java.lang, "Thread", null, Runnable);
\r
20 c$.nextThreadNum = Clazz.defineMethod (c$, "nextThreadNum",
\r
22 return java.lang.Thread.threadInitNumber++;
\r
24 c$.nextThreadID = Clazz.defineMethod (c$, "nextThreadID",
\r
26 return ++java.lang.Thread.threadSeqNumber;
\r
28 c$.currentThread = Clazz.defineMethod (c$, "currentThread",
\r
30 if (java.lang.Thread.thisThread == null) {
\r
31 java.lang.Thread.thisThread = new java.lang.Thread ("master");
\r
32 java.lang.Thread.thisThread.setPriority (5);
\r
33 }return java.lang.Thread.thisThread;
\r
35 c$.yield = Clazz.defineMethod (c$, "yield",
\r
38 c$.sleep = Clazz.defineMethod (c$, "sleep",
\r
41 c$.sleep = Clazz.defineMethod (c$, "sleep",
\r
42 function (millis, nanos) {
\r
44 throw new IllegalArgumentException ("timeout value is negative");
\r
45 }if (nanos < 0 || nanos > 999999) {
\r
46 throw new IllegalArgumentException ("nanosecond timeout value out of range");
\r
47 }if (nanos >= 500000 || (nanos != 0 && millis == 0)) {
\r
49 }java.lang.Thread.sleep (millis);
\r
51 Clazz.defineMethod (c$, "init",
\r
52 function (g, target, name, stackSize) {
\r
53 this.init (g, target, name, stackSize, null);
\r
54 }, "java.lang.ThreadGroup,Runnable,~S,~N");
\r
55 Clazz.defineMethod (c$, "init",
\r
56 function (g, target, name, stackSize, acc) {
\r
57 var parent = (java.lang.Thread.thisThread == null ? null : java.lang.Thread.thisThread);
\r
59 if (g == null && parent != null) {
\r
60 g = parent.getThreadGroup ();
\r
62 g = this.newThreadGroup (null, name);
\r
67 this.priority = parent.getPriority ();
\r
69 this.target = target;
\r
70 this.setPriority (this.priority);
\r
71 this.tid = java.lang.Thread.nextThreadID ();
\r
73 }, "java.lang.ThreadGroup,Runnable,~S,~N,~O");
\r
74 Clazz.defineMethod (c$, "newThreadGroup",
\r
75 function (group, name) {
\r
76 return new java.lang.ThreadGroup (group, name);
\r
77 }, "java.lang.ThreadGroup,~S");
\r
78 Clazz.makeConstructor (c$,
\r
80 this.init (null, null, "Thread-" + java.lang.Thread.nextThreadNum (), 0);
\r
82 Clazz.makeConstructor (c$,
\r
84 this.init (null, target, "Thread-" + java.lang.Thread.nextThreadNum (), 0);
\r
86 Clazz.makeConstructor (c$,
\r
87 function (group, target) {
\r
88 this.init (group, target, "Thread-" + java.lang.Thread.nextThreadNum (), 0);
\r
89 }, "java.lang.ThreadGroup,Runnable");
\r
90 Clazz.makeConstructor (c$,
\r
92 this.init (null, null, name, 0);
\r
94 Clazz.makeConstructor (c$,
\r
95 function (group, name) {
\r
96 this.init (group, null, name, 0);
\r
97 }, "java.lang.ThreadGroup,~S");
\r
98 Clazz.makeConstructor (c$,
\r
99 function (target, name) {
\r
100 this.init (null, target, name, 0);
\r
102 Clazz.makeConstructor (c$,
\r
103 function (group, target, name) {
\r
104 this.init (group, target, name, 0);
\r
105 }, "java.lang.ThreadGroup,Runnable,~S");
\r
106 Clazz.makeConstructor (c$,
\r
107 function (group, target, name, stackSize) {
\r
108 this.init (group, target, name, stackSize);
\r
109 }, "java.lang.ThreadGroup,Runnable,~S,~N");
\r
110 Clazz.defineMethod (c$, "start",
\r
112 if (this.threadStatus != 0 || this !== this.me) throw new IllegalThreadStateException ();
\r
113 this.group.add (this);
\r
115 if (this.stopBeforeStart) {
\r
116 this.stop0 (this.throwableFromStop);
\r
118 Clazz.defineMethod (c$, "start0",
\r
121 Clazz.defineMethod (c$, "run",
\r
123 if (this.target != null) {
\r
124 this.target.run ();
\r
126 Clazz.defineMethod (c$, "stop",
\r
128 if ((this.threadStatus != 0) && !this.isAlive ()) {
\r
130 }this.stop1 ( new ThreadDeath ());
\r
132 Clazz.defineMethod (c$, "stop",
\r
136 Clazz.defineMethod (c$, "stop1",
\r
138 if (this.threadStatus != 0) {
\r
143 throw new NullPointerException ();
\r
144 }this.stopBeforeStart = true;
\r
145 this.throwableFromStop = th;
\r
147 Clazz.defineMethod (c$, "interrupt",
\r
149 this.interrupt0 ();
\r
151 c$.interrupted = Clazz.defineMethod (c$, "interrupted",
\r
153 return java.lang.Thread.currentThread ().isInterruptedB (true);
\r
155 Clazz.defineMethod (c$, "isInterrupted",
\r
157 return this.isInterruptedB (false);
\r
159 Clazz.defineMethod (c$, "isInterruptedB",
\r
160 function (clearInterrupted) {
\r
161 var wasInt = this.$interrupted;
\r
162 if (clearInterrupted) this.$interrupted = false;
\r
165 Clazz.defineMethod (c$, "destroy",
\r
167 throw new NoSuchMethodError ();
\r
169 Clazz.defineMethod (c$, "isAlive",
\r
173 Clazz.defineMethod (c$, "suspend",
\r
175 this.checkAccess ();
\r
178 Clazz.defineMethod (c$, "resume",
\r
180 this.checkAccess ();
\r
183 Clazz.defineMethod (c$, "setPriority",
\r
184 function (newPriority) {
\r
186 this.checkAccess ();
\r
187 if (newPriority > 10 || newPriority < 1) {
\r
188 throw new IllegalArgumentException ();
\r
189 }if ((g = this.getThreadGroup ()) != null) {
\r
190 if (newPriority > g.getMaxPriority ()) {
\r
191 newPriority = g.getMaxPriority ();
\r
192 }this.setPriority0 (this.priority = newPriority);
\r
194 Clazz.defineMethod (c$, "getPriority",
\r
196 return this.priority;
\r
198 Clazz.defineMethod (c$, "setName",
\r
200 this.checkAccess ();
\r
203 Clazz.defineMethod (c$, "getName",
\r
207 Clazz.defineMethod (c$, "getThreadGroup",
\r
211 c$.activeCount = Clazz.defineMethod (c$, "activeCount",
\r
213 return java.lang.Thread.currentThread ().getThreadGroup ().activeCount ();
\r
215 c$.enumerate = Clazz.defineMethod (c$, "enumerate",
\r
216 function (tarray) {
\r
217 return java.lang.Thread.currentThread ().getThreadGroup ().enumerate (tarray);
\r
219 Clazz.defineMethod (c$, "countStackFrames",
\r
223 Clazz.defineMethod (c$, "join",
\r
224 function (millis) {
\r
225 var base = System.currentTimeMillis ();
\r
228 throw new IllegalArgumentException ("timeout value is negative");
\r
229 }swingjs.JSToolkit.warn ("Cannot wait in Thread");
\r
231 while (this.isAlive ()) {
\r
235 while (this.isAlive ()) {
\r
236 var delay = millis - now;
\r
239 }this.wait (delay);
\r
240 now = System.currentTimeMillis () - base;
\r
243 Clazz.defineMethod (c$, "join",
\r
244 function (millis, nanos) {
\r
246 throw new IllegalArgumentException ("timeout value is negative");
\r
247 }if (nanos < 0 || nanos > 999999) {
\r
248 throw new IllegalArgumentException ("nanosecond timeout value out of range");
\r
249 }if (nanos >= 500000 || (nanos != 0 && millis == 0)) {
\r
251 }this.join (millis);
\r
253 Clazz.defineMethod (c$, "join",
\r
257 c$.dumpStack = Clazz.defineMethod (c$, "dumpStack",
\r
259 new Exception ("Stack trace").printStackTrace ();
\r
261 Clazz.defineMethod (c$, "setDaemon",
\r
263 this.checkAccess ();
\r
264 if (this.isAlive ()) {
\r
265 throw new IllegalThreadStateException ();
\r
268 Clazz.defineMethod (c$, "isDaemon",
\r
270 return this.daemon;
\r
272 Clazz.defineMethod (c$, "checkAccess",
\r
275 Clazz.overrideMethod (c$, "toString",
\r
277 var group = this.getThreadGroup ();
\r
278 if (group != null) {
\r
279 return "Thread[" + this.getName () + "," + this.getPriority () + "," + group.getName () + "]";
\r
281 return "Thread[" + this.getName () + "," + this.getPriority () + "," + "" + "]";
\r
283 Clazz.defineMethod (c$, "getContextClassLoader",
\r
287 Clazz.defineMethod (c$, "setContextClassLoader",
\r
290 c$.holdsLock = Clazz.defineMethod (c$, "holdsLock",
\r
294 Clazz.defineMethod (c$, "getStackTrace",
\r
296 return ( new Exception ()).getStackTrace ();
\r
298 c$.getAllStackTraces = Clazz.defineMethod (c$, "getAllStackTraces",
\r
300 var threads = java.lang.Thread.getThreads ();
\r
301 var traces = java.lang.Thread.dumpThreads (threads);
\r
302 var m = new java.util.HashMap (threads.length);
\r
303 for (var i = 0; i < threads.length; i++) {
\r
304 var stackTrace = traces[i];
\r
305 if (stackTrace != null) {
\r
306 m.put (threads[i], stackTrace);
\r
310 c$.dumpThreads = Clazz.defineMethod (c$, "dumpThreads",
\r
311 function (threads) {
\r
314 c$.getThreads = Clazz.defineMethod (c$, "getThreads",
\r
318 Clazz.defineMethod (c$, "getId",
\r
322 Clazz.defineMethod (c$, "getState",
\r
324 switch (this.threadStatus) {
\r
326 return java.lang.Thread.State.NEW;
\r
328 return java.lang.Thread.State.RUNNABLE;
\r
331 return java.lang.Thread.State.TERMINATED;
\r
333 return java.lang.Thread.State.TIMED_WAITING;
\r
335 return java.lang.Thread.State.WAITING;
\r
338 c$.setDefaultUncaughtExceptionHandler = Clazz.defineMethod (c$, "setDefaultUncaughtExceptionHandler",
\r
340 java.lang.Thread.defaultUncaughtExceptionHandler = eh;
\r
341 }, "java.lang.Thread.UncaughtExceptionHandler");
\r
342 c$.getDefaultUncaughtExceptionHandler = Clazz.defineMethod (c$, "getDefaultUncaughtExceptionHandler",
\r
344 return java.lang.Thread.defaultUncaughtExceptionHandler;
\r
346 Clazz.defineMethod (c$, "getUncaughtExceptionHandler",
\r
348 return this.uncaughtExceptionHandler != null ? this.uncaughtExceptionHandler : this.group;
\r
350 Clazz.defineMethod (c$, "setUncaughtExceptionHandler",
\r
352 this.checkAccess ();
\r
353 this.uncaughtExceptionHandler = eh;
\r
354 }, "java.lang.Thread.UncaughtExceptionHandler");
\r
355 Clazz.defineMethod (c$, "setPriority0",
\r
356 function (newPriority) {
\r
358 Clazz.defineMethod (c$, "stop0",
\r
360 this.stopped = true;
\r
362 Clazz.defineMethod (c$, "suspend0",
\r
365 Clazz.defineMethod (c$, "resume0",
\r
368 Clazz.defineMethod (c$, "interrupt0",
\r
370 this.$interrupted = true;
\r
372 Clazz.pu$h(self.c$);
\r
373 c$ = Clazz.declareType (java.lang.Thread, "State", Enum);
\r
374 Clazz.defineEnumConstant (c$, "NEW", 0, []);
\r
375 Clazz.defineEnumConstant (c$, "RUNNABLE", 1, []);
\r
376 Clazz.defineEnumConstant (c$, "BLOCKED", 2, []);
\r
377 Clazz.defineEnumConstant (c$, "WAITING", 3, []);
\r
378 Clazz.defineEnumConstant (c$, "TIMED_WAITING", 4, []);
\r
379 Clazz.defineEnumConstant (c$, "TERMINATED", 5, []);
\r
381 Clazz.declareInterface (java.lang.Thread, "UncaughtExceptionHandler");
\r
382 Clazz.defineStatics (c$,
\r
383 "threadInitNumber", 0,
\r
384 "threadSeqNumber", 0,
\r
385 "thisThread", null,
\r
387 "NORM_PRIORITY", 5,
\r
388 "MAX_PRIORITY", 10,
\r
389 "defaultUncaughtExceptionHandler", null);
\r