--- old/src/share/classes/java/awt/EventQueue.java 2011-08-24 13:18:40.831390201 +0200 +++ new/src/share/classes/java/awt/EventQueue.java 2011-08-24 13:18:40.546393765 +0200 @@ -46,7 +46,8 @@ import sun.awt.AWTAccessor; import java.util.concurrent.locks.Condition; -import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.atomic.AtomicInteger; import java.security.AccessControlContext; import java.security.ProtectionDomain; @@ -99,12 +100,7 @@ * @since 1.1 */ public class EventQueue { - - // From Thread.java - private static int threadInitNumber; - private static synchronized int nextThreadNum() { - return threadInitNumber++; - } + private static final AtomicInteger threadInitNumber = new AtomicInteger(0); private static final int LOW_PRIORITY = 0; private static final int NORM_PRIORITY = 1; @@ -141,7 +137,7 @@ * all the EventQueues from the AppContext. Synchronization on any particular * event queue(s) is not enough: we should lock the whole stack. */ - private final Lock pushPopLock; + private final ReentrantLock pushPopLock; private final Condition pushPopCond; /* @@ -175,9 +171,9 @@ * Non-zero if a thread is waiting in getNextEvent(int) for an event of * a particular ID to be posted to the queue. */ - private int waitForID; + private volatile int waitForID; - private final String name = "AWT-EventQueue-" + nextThreadNum(); + private final String name = "AWT-EventQueue-" + threadInitNumber.getAndIncrement(); private static final PlatformLogger eventLog = PlatformLogger.getLogger("java.awt.event.EventQueue"); @@ -206,7 +202,7 @@ * completes thus causing mess in thread group to appcontext mapping. */ - pushPopLock = (Lock)AppContext.getAppContext().get(AppContext.EVENT_QUEUE_LOCK_KEY); + pushPopLock = (ReentrantLock)AppContext.getAppContext().get(AppContext.EVENT_QUEUE_LOCK_KEY); pushPopCond = (Condition)AppContext.getAppContext().get(AppContext.EVENT_QUEUE_COND_KEY); } @@ -514,7 +510,9 @@ AWTAutoShutdown.getInstance().notifyThreadFree(dispatchThread); pushPopCond.await(); } finally { - pushPopLock.unlock(); + if(pushPopLock.isHeldByCurrentThread()) { + pushPopLock.unlock(); + } } } while(true); } @@ -569,7 +567,9 @@ pushPopCond.await(); waitForID = 0; } finally { - pushPopLock.unlock(); + if(pushPopLock.isHeldByCurrentThread()) { + pushPopLock.unlock(); + } } } while(true); } --- old/src/share/classes/java/awt/EventDispatchThread.java 2011-08-24 13:18:41.586380762 +0200 +++ new/src/share/classes/java/awt/EventDispatchThread.java 2011-08-24 13:18:41.310384212 +0200 @@ -35,7 +35,7 @@ import sun.awt.AWTAutoShutdown; import sun.awt.SunToolkit; -import java.util.Vector; +import java.util.ArrayList; import sun.util.logging.PlatformLogger; import sun.awt.dnd.SunDragSourceContextPeer; @@ -66,11 +66,10 @@ private EventQueue theQueue; private boolean doDispatch = true; - private boolean threadDeathCaught = false; private static final int ANY_EVENT = -1; - private Vector eventFilters = new Vector(); + private ArrayList eventFilters = new ArrayList(); EventDispatchThread(ThreadGroup group, String name, EventQueue queue) { super(group, name); @@ -94,7 +93,7 @@ }); } finally { EventQueue eq = getEventQueue(); - if (eq.detachDispatchThread(this) || threadDeathCaught) { + if (eq.detachDispatchThread(this) || isInterrupted()) { break; } } @@ -216,9 +215,7 @@ return true; } catch (ThreadDeath death) { - threadDeathCaught = true; - return false; - + throw death; } catch (InterruptedException interruptedException) { return false; // AppContext.dispose() interrupts all