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