<AWT Dev> deadlock involving a mutex Lock from java.awt.EventQueue and SunToolkit.PostEventQueue

Peter Levart peter.levart at gmail.com
Thu Jun 28 00:33:32 PDT 2012


This started as a bug report on the NetBeans bugzila:

http://netbeans.org/bugzilla/show_bug.cgi?id=214872

But is seems that it is caused by synchronization changes to 
java.awt.EventQueue in JDK 1.7 (JDK 1.6 seems not to be affected).

To quote the part of the NetBeans bug:

I think that the root of the problem is in JDK 1.7, namely in the method:

java.awt.EventQueue.detachDispatchThread

...where it calls SunToolkit.isPostEventQueueEmpty() while holding global
"pushPopLock".

The static method SunToolkit.isPostEventQueueEmpty() invokes a synchronized
method on a singleton PostEventQueue object. Also other methods on this
singleton PostEventQueue are synchronized and some of them (for example
PostEventQueue.flush() invoked from static SunToolkit.flushPendingEvents()) are
also synchronized and call into the java.awt.EventQueue which tries to get the
global "pushPopLock" - hence the deadlock.

SunToolkit.isPostEventQueueEmpty() (or any of it's methods that delegate to
PostEventQueue singleton) should not be called while holding global
"pushPopLock" in java.awt.EventQueue...

My proposal to fix this bug is to rewrite the SunToolkit.PostEventQueue to use
the same global "pushPopLock" Lock instance that java.awt.EnetQueue uses for
it's synchronization instead of "synchronized" instance methods...


Regards, Peter




More information about the awt-dev mailing list