Open DanHeidinga opened 4 years ago
If it's important to add to Java 8, a properly crafted wait/notify solution could be produced. The issue with just using wait/notify without protecting a state variable is that the notify could be lost (if the main thread notifies before the daemon gets into wait, the daemon would not exit).
The test should not depend on the exit code, as the main thread may well win the race to shut the VM down, depending on thread scheduling.
Original test code:
public class Launchee {
public static void main(String[] args) throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
Thread t = new Thread() {
@Override
public void run() {
latch.countDown();
System.exit(1);
}
};
t.setDaemon(true);
t.start();
latch.await();
}
}
I have no idea how to add tests that aren't in the JVMTI framework (which isn't appropriate here), so I suggest merging this and opening a new issue to get the test added.
For the record, I modified the test to use wait/notify rather than the latch (which doesn't exist in java 8). This isn't realiable enough to put into an automated test, so perhaps the original test should be added for JDK11+.
Originally posted by @gacholio in https://github.com/eclipse/openj9/pull/10273#issuecomment-665722821