When running on OSX (10.6.2) I've notice my SWT/JFace application doesn't exit cleanly - the application icon remains in the dock and I must forcefully quit the application. It terminates cleanly on WIndows/Linux. I'm using Java/6.
I've boiled the issue down to my use of java.awt.Desktop. I use this to open up folders in Explorer/Finder and the default browser.
If I run this snippet all works as expected and the JVM exits;
public class Main {
public static void main(String args[]) {
System.out.println(Desktop.isDesktopSupported()); /* true */
}
}
But if I run the same snippet with some SWT:
public class Main {
public static void main(String args[]) {
Display d = new Display();
Shell s = new Shell(d);
System.out.println(Desktop.isDesktopSupported()); /* true */
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch()) {
d.sleep();
}
}
d.dispose();
}
}
Then the JVM does not exit (on OSX). The only non-daemon thread is AWT shutdown:
"AWT-Shutdown" prio=5 tid=0x030b5c00 nid=0xb0b20000 in Object.wait() [0xb0b1f000]
java.lang.Thread.State: WAITING (on object monitor)
at java.lang.Object.wait(Native Method)
- waiting on <0x30180668> (a java.lang.Object)
at java.lang.Object.wait(Object.java:485)
at sun.awt.AWTAutoShutdown.run(AWTAutoShutdown.java:259)
- locked <0x30180668> (a java.lang.Object)
at java.lang.Thread.run(Thread.java:637)
Interestingly I see these logs printed to the console when the JVM starts:
2011-02-02 09:24:11.802 java[398:1507] [Java CocoaComponent compatibility mode]: Enabled
2011-02-02 09:24:11.831 java[398:1507] [Java CocoaComponent compatibility mode]: Setting timeout for SWT to 0.100000
If I run with "-Djava.awt.headless=true" then the JVM does exit. But the desktop is now disabled (isDesktopSupported() returns false).
Is there a known workaround for this issue? Or an SWT-friendly technique to launch explorer and the default browser?
Ben