Skip to content

Commit 95d7f3c

Browse files
committed
fix for System.exit needs to stop running threads
1 parent 835ce54 commit 95d7f3c

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

sources/net.sf.j2s.java.core/src/java/lang/Thread.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private static synchronized int nextThreadNum() {
204204
* Thread ID
205205
*/
206206
private long tid;
207-
207+
208208
/* For generating thread ID */
209209
private static long threadSeqNumber;
210210
public static Thread thisThread;
@@ -277,7 +277,7 @@ private static synchronized long nextThreadID() {
277277
public static Thread currentThread() {
278278
/**
279279
* @j2sNative
280-
*if (java.lang.Thread.thisThread == "working")
280+
*if (java.lang.Thread.thisThread === "working")
281281
* return null;
282282
*
283283
*

sources/net.sf.j2s.java.core/src/swingjs/JSToolkit.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,15 @@ public static Object getPostEventQueue(boolean isPost) {
106106
AppContext.EVENT_QUEUE_KEY));
107107
}
108108

109+
/**
110+
* From System.exit()
111+
*/
109112
public static void exit() {
113+
/**
114+
* @j2sNative
115+
*
116+
* Thread.thisThread.group.systemExited = true;
117+
*/
110118
JSUtil.getAppletViewer().exit();
111119
}
112120

@@ -345,6 +353,7 @@ public static void dispatchEvent(AWTEvent event, Object src, boolean andWait) {
345353
/**
346354
* @j2sNative
347355
*
356+
*
348357
* f = function()
349358
* {
350359
* if
@@ -373,7 +382,9 @@ public static int dispatch(Object f, int msDelay, int id) {
373382
/**
374383
* @j2sNative
375384
*
376-
* var thread = java.lang.Thread.thisThread;
385+
* var thread = Thread.thisThread;
386+
* if (thread.group.systemExited)
387+
* return;
377388
* var thread0 = thread;
378389
* var id0 = SwingJS.eventID || 0;
379390
* var ff = function(_JSToolkit_setTimeout) {
@@ -387,9 +398,10 @@ public static int dispatch(Object f, int msDelay, int id) {
387398
* } catch (e) {
388399
* var s = "JSToolkit.dispatch(" + id +"): " + e + "\n" + (e.getStackTrace ? e.getStackTrace() + "\n" : "") + (!!e.stack ? e.stack : "");
389400
* System.out.println(s);
390-
* alert(s)}
401+
* alert(s);
402+
* }
391403
* SwingJS.eventID = id0;
392-
* java.lang.Thread.thisThread = thread0;
404+
* Thread.thisThread = thread0;
393405
* };
394406
* return (msDelay == -1 ? ff() : setTimeout(ff, msDelay));
395407
*
@@ -413,7 +425,9 @@ private static void invokeAndWait(JSFunction f, int id) {
413425
/**
414426
* @j2sNative
415427
*
416-
* var thread = java.lang.Thread.thisThread;
428+
* var thread = Thread.thisThread;
429+
* if (thread.group.systemExited)
430+
* return;
417431
* var thread0 = thread;
418432
* (function(_JSToolkit_setTimeout) {
419433
* var id0 = SwingJS.eventID || 0;
@@ -424,7 +438,7 @@ private static void invokeAndWait(JSFunction f, int id) {
424438
* else
425439
* f();
426440
* SwingJS.eventID = id0;
427-
* java.lang.Thread.thisThread = thread0;
441+
* Thread.thisThread = thread0;
428442
* })();
429443
*
430444
*

0 commit comments

Comments
 (0)