Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/jvm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1360,14 +1360,15 @@ export class JVM {
// nothing left to report to
}
}
// Main must be joinable before DestroyJavaVM waits for other threads.
yield* this.exitThread(t);
// DestroyJavaVM: wait for the other non-daemon threads, then shut down.
while (this.nonDaemonAlive(t)) {
yield t.block(new Promise<void>((r) => {
const check = () => (this.nonDaemonAlive(t) ? setTimeout(check, 5) : r());
check();
}));
}
yield* this.exitThread(t);
yield t.call(boot("java/lang/Shutdown").methodMap.get("shutdown()V")!);
this.halt(code);
}
Expand Down
15 changes: 15 additions & 0 deletions test/java/MainThreadExit.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
public class MainThreadExit {
public static void main(String[] args) {
Thread main = Thread.currentThread();
main.setUncaughtExceptionHandler((thread, error) -> System.out.println("uncaught: " + error.getMessage()));
new Thread(() -> {
try {
main.join();
System.out.println("main alive: " + main.isAlive());
} catch (InterruptedException e) {
throw new AssertionError(e);
}
}).start();
throw new RuntimeException("main failed");
}
}
1 change: 1 addition & 0 deletions test/jtreg/passing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1053,6 +1053,7 @@ java/lang/Thread/SleepSanity.java
java/lang/Thread/SleepWithDuration.java
java/lang/Thread/ThreadStateTest.java
java/lang/Thread/ThreadStopTest.java
java/lang/Thread/UncaughtExceptionsTest.java
java/lang/Thread/virtual/Collectable.java
java/lang/Thread/virtual/Locking.java
java/lang/Thread/virtual/Reflection.java
Expand Down
Loading