Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » JVM not closing on OSX when using java.awt.Desktop & SWT(JVM not closing on OSX when using java.awt.Desktop & SWT)
JVM not closing on OSX when using java.awt.Desktop & SWT [message #651963] Wed, 02 February 2011 09:54 Go to next message
Ben Rowlands is currently offline Ben RowlandsFriend
Messages: 3
Registered: February 2011
Junior Member
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
Re: JVM not closing on OSX when using java.awt.Desktop & SWT [message #652136 is a reply to message #651963] Wed, 02 February 2011 18:27 Go to previous message
Ben Rowlands is currently offline Ben RowlandsFriend
Messages: 3
Registered: February 2011
Junior Member
Quote:
Is there a known workaround for this issue? Or an SWT-friendly technique to launch explorer and the default browser?


If anyone else faces the same problem I just noticed the Program class in SWT opens Explorer/Finder in given a directory and opens the default browser. So I can avoid AWT Desktop.

Failing that, System.exit() also solves the hanging AWT-Shutdown thread.
Previous Topic:compression in java using eclipse pls help
Next Topic:Sending email with attachment using default email client
Goto Forum:
  


Current Time: Mon Apr 06 02:50:29 GMT 2020

Powered by FUDForum. Page generated in 0.01649 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top