开发者

What could cause Java to keep running after return

I have this problem when I do some special GUI interaction. Here is my situation: I use one dialog. I don't call

System.exit() but leave the application later with a return. Normally the JVM then exists when it sees that no more non-deaemon threads are running. But after using this dialog, it does not work.

I am 100% shure that a dispose() is called on the dialog in question and also on the main frame of the application. I get this both in an IDE 开发者_如何学Pythonand when running from the command line. I can kill it with a button press in the IDE, or with Ctrl-C from the command line.

But it would of course be better if the JVM correctly terminates itself before delivering the application.

Any clues, is this a known problem? I am using JDK 1.7, but the problem show already up in JDK 1.6.

Best Regards

P.S.: Just reading: http://download.oracle.com/javase/1.4.2/docs/api/java/awt/doc-files/AWTThreadIssues.html There have been similar issues in the past. Maybe this is a new issue. The issues in the past were: Other packages can create displayable components for internal needs and never make them undisplayable. See 4515058, 4671025, and 4465537. I will try some along an explicit setVisible(false) of the pop up menu.


Are you sure the pop up is destroyed and not just hidden? I believe the default action is to hide, and setting the default close operation to JFRAME.EXIT_ON_CLOSE might solve it.

Another way of diagnosing the problem could be to use a profiler, such as the one shipped with Netbeans. Use live view and a debug point just before application should terminate, and you can inspect the live objects.


The default action when you close a frame is to just hide it. The UI thread is still alive.

If you want the JVM to exit when you close the frame you make (possibly your "popup"?), you have to explicitly say so, e.g. by doing frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); , more docs here. Possibly you only need the DISPOSE_ON_CLOSE as the defaultCloseOperation.

An other alternative is to add a windowListener to the frame, and decide the proper action yourself when the frame is closed.


Sounds like at least one thread is blocking and can't respond to an interrupt. Perhaps using .getState() on the thread in question may shed some light on the problem.

http://download.oracle.com/javase/6/docs/api/java/lang/Thread.html#getState%28%29


I had the same problem, calling dispose() in a EventQueue.invokeLater(new Runnable() {...} resolved it for me

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜