JDK-8081485 : EDT auto shutdown is broken in case of new event queue usage
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 8u45
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: x86
  • Submitted: 2015-05-15
  • Updated: 2016-01-14
  • Resolved: 2015-09-09
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.
JDK 8 JDK 9
8u72Fixed 9 b83Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Darwin unit-714.labs.intellij.net 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64

A DESCRIPTION OF THE PROBLEM :
The problem is that java application which runs in headless mode doesn't terminate on it's main thread completion under the circumstances below:
* EventQueue.push(new EventQueue()) is called on a system EventQueue
* an event is posted to the EventQueue

ADDITIONAL REGRESSION INFORMATION: 
The same code works fine under os x java6:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the application which code is provided above

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The application is successfully terminated
ACTUAL -
The application hangs

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Thread dump (relevant part - not-daemon thread):
"AWT-EventQueue-0@563" prio=6 tid=0xe nid=NA waiting
  java.lang.Thread.State: WAITING
	  at sun.misc.Unsafe.park(Unsafe.java:-1)
	  at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
	  at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
	  at java.awt.EventQueue.getNextEvent(EventQueue.java:554)
	  at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:170)
	  at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
	  at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
	  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
	  at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
	  at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package org;

import java.awt.*;

public class Xxx {
    public static void main(String[] args) throws Exception {
        System.setProperty("java.awt.headless", "true");
        final EventQueue systemQueue = Toolkit.getDefaultToolkit().getSystemEventQueue();
        // Current java process is successfully terminated if the line below is commented.
        systemQueue.push(new EventQueue());
        EventQueue.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                System.out.println("Activated EDT");
            }
        });
        System.out.println("After EDT activation");
    }
}

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


Comments
Reason: the EventQueue.push() first checks if the EDT for the top EventQeue exists (to transfer it to the new EventQueue) and then implicitly starts it. Fix: do posting of dummy event only in case if the EventQueue had the EDT
01-07-2015

Webrev: http://cr.openjdk.java.net/~anashaty/8081485/webrev.00/
01-07-2015

The problem is reproducible on 8u60 and 9-b66.
29-05-2015