<AWT Dev> [7u6] Review request for 7177040: Deadlock between PostEventQueue.noEvents, EventQueue.isDispatchThread and SwingUtilities.invokeLater

Oleg Pekhovskiy oleg.pekhovskiy at oracle.com
Wed Jul 11 08:24:40 PDT 2012


Please review the fix for CR:


The idea of the fix is that there are two concurrent threads that try to 
get two synchronization objects EventQueue.pushPopLock and 
PostEventQueue itself.
For NetBeans these threads are (EDT & WarmUp) or (EDT & TimerQueue).
Problem happens when EDT is interrupted and goes to 
EventQueue.detachDispatchThread() where EventQueue.pushPopLock is owned and
EDT is waiting to own PostEventQueue when calling 
SunToolkit.isPostEventQueueEmpty() -> PostEventQueue.noEvents().
At the same time another thread calls EventQueue.postEvent() that calls 
EventQueue.flushPendingEvents() -> PostEventQueue.flush() where 
PostEventQueue is owned
and another thread is waiting to own EventQueue.pushPopLock when calling 
EventQueue.postEvent() -> EventQueue.postEventPrivate().

To avoid potential deadlock I moved synchronization out of postEvent()'s 
cycle in PostEventQueue.flush(),
but to be clear about the existence of Events that are not posted to 
EventQueue yet I added PostEventQueue.isPending flag that is true until 
the end of the cycle.

There are only two classes that utilize PostEventQueue.flush() method: 
SunToolkit.flushPendingEvents() and SunToolkitSubclass.flushPendingEvents().
They are both synchronized by static SunToolkit.flushLock. That 
eliminates the situation when we have overlapped calls of 


More information about the awt-dev mailing list