JDK-7097333 : Adding an EventQueue on the AWT queue prevents JVM from terminate on exit
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7,8,9
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_vista
  • CPU: x86
  • Submitted: 2011-10-02
  • Updated: 2021-07-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [version 6.0.6002]

A DESCRIPTION OF THE PROBLEM :
Adding a EventQueue on the AWT queue prevents JVM from terminate on exit.
When the last window is dispose, it remains a living thread (AWT-EventQueue-0) that prevents the JVM from terminate.



REGRESSION.  Last worked in version 6u26

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Add a new EventQueue like :
EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
queue.push(new EventQueue() {
  @Override
  protected void dispatchEvent(AWTEvent event) {
    try {
      super.dispatchEvent(event);
    } catch (Throwable t) {
      // Log the error
    }
  }
});


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JVM should terminate when closing the last window
ACTUAL -
It remains a living thread: AWT-EventQueue-0

ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error message

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.AWTEvent;
import java.awt.EventQueue;
import java.awt.Toolkit;

import javax.swing.JFrame;

public class Test {
	public static void main(String[] args) {
		// Install an exception logger on the AWT event queue.
		EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue();
		queue.push(new EventQueue() {
			@Override
			protected void dispatchEvent(AWTEvent event) {
				try {
					super.dispatchEvent(event);
				} catch (Throwable t) {
					// Log the error
				}
			}
		});
		// Schedule a job for the event-dispatching thread:
		// creating and showing this application's GUI.
		javax.swing.SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame("Frame");
				frame.setVisible(true);
				frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
			}
		});
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
A very ugly workaround, add this in the new EventQueue dispatchEvent method :
if (event.getClass().getName().startsWith("sun.awt.AWTAutoShutdown")) {
  System.exit(0); //TODO
}

Comments
not a regression for 8 and 9
12-12-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

EVALUATION I see that the problem is reproducible at least with jdk 7b147 and further releases. If I push a new EventQueue form EDT the application exits without problm. So it could be considered as a workaround. The problem could be connected with 7081670.
01-11-2011

WORK AROUND javax.swing.SwingUtilities.invokeLater(new Runnable() { @Override public void run() { EventQueue queue = Toolkit.getDefaultToolkit().getSystemEventQueue(); queue.push(new EventQueue() { @Override protected void dispatchEvent(AWTEvent event) { try { super.dispatchEvent(event); } catch (Throwable t) { t.printStackTrace(); } } }); } });
01-11-2011