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
}