11/*
2- * Copyright (c) 1996, 2025 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 1996, 2026 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
4040
4141import java .util .concurrent .locks .Condition ;
4242import java .util .concurrent .locks .Lock ;
43+ import java .util .concurrent .locks .ReentrantLock ;
4344import java .util .concurrent .atomic .AtomicInteger ;
4445
4546/**
@@ -112,11 +113,11 @@ public class EventQueue {
112113
113114 /*
114115 * A single lock to synchronize the push()/pop() and related operations with
115- * all the EventQueues from the AppContext . Synchronization on any particular
116+ * all the EventQueues. Synchronization on any particular
116117 * event queue(s) is not enough: we should lock the whole stack.
117118 */
118- private final Lock pushPopLock ;
119- private final Condition pushPopCond ;
119+ private static final Lock pushPopLock = new ReentrantLock () ;
120+ private static final Condition pushPopCond = pushPopLock . newCondition () ;
120121
121122 /*
122123 * Dummy runnable to wake up EDT from getNextEvent() after
@@ -156,11 +157,6 @@ public void run() {
156157 */
157158 private volatile int waitForID ;
158159
159- /*
160- * AppContext corresponding to the queue.
161- */
162- private final AppContext appContext ;
163-
164160 private final String name = "AWT-EventQueue-" + threadInitNumber .getAndIncrement ();
165161
166162 private FwDispatcher fwDispatcher ;
@@ -222,18 +218,6 @@ public EventQueue() {
222218 for (int i = 0 ; i < NUM_PRIORITIES ; i ++) {
223219 queues [i ] = new Queue ();
224220 }
225- /*
226- * NOTE: if you ever have to start the associated event dispatch
227- * thread at this point, be aware of the following problem:
228- * If this EventQueue instance is created in
229- * SunToolkit.createNewAppContext() the started dispatch thread
230- * may call AppContext.getAppContext() before createNewAppContext()
231- * completes thus causing mess in thread group to appcontext mapping.
232- */
233-
234- appContext = AppContext .getAppContext ();
235- pushPopLock = (Lock )appContext .get (AppContext .EVENT_QUEUE_LOCK_KEY );
236- pushPopCond = (Condition )appContext .get (AppContext .EVENT_QUEUE_COND_KEY );
237221 }
238222
239223 /**
@@ -247,7 +231,7 @@ public EventQueue() {
247231 * @throws NullPointerException if {@code theEvent} is {@code null}
248232 */
249233 public void postEvent (AWTEvent theEvent ) {
250- SunToolkit .flushPendingEvents (appContext );
234+ SunToolkit .flushPendingEvents ();
251235 postEventPrivate (theEvent );
252236 }
253237
@@ -532,7 +516,7 @@ public AWTEvent getNextEvent() throws InterruptedException {
532516 * of the synchronized block to avoid deadlock when
533517 * event queues are nested with push()/pop().
534518 */
535- SunToolkit .flushPendingEvents (appContext );
519+ SunToolkit .flushPendingEvents ();
536520 pushPopLock .lock ();
537521 try {
538522 AWTEvent event = getNextEventPrivate ();
@@ -572,7 +556,7 @@ AWTEvent getNextEvent(int id) throws InterruptedException {
572556 * of the synchronized block to avoid deadlock when
573557 * event queues are nested with push()/pop().
574558 */
575- SunToolkit .flushPendingEvents (appContext );
559+ SunToolkit .flushPendingEvents ();
576560 pushPopLock .lock ();
577561 try {
578562 for (int i = 0 ; i < NUM_PRIORITIES ; i ++) {
@@ -869,8 +853,8 @@ public void push(EventQueue newEventQueue) {
869853 newEventQueue .previousQueue = topQueue ;
870854 topQueue .nextQueue = newEventQueue ;
871855
872- if (appContext . get ( AppContext . EVENT_QUEUE_KEY ) == topQueue ) {
873- appContext . put ( AppContext . EVENT_QUEUE_KEY , newEventQueue ) ;
856+ if (SunToolkit . currentEventQueue == topQueue ) {
857+ SunToolkit . currentEventQueue = newEventQueue ;
874858 }
875859
876860 pushPopCond .signalAll ();
@@ -929,8 +913,8 @@ protected void pop() throws EmptyStackException {
929913 topQueue .dispatchThread .setEventQueue (prevQueue );
930914 }
931915
932- if (appContext . get ( AppContext . EVENT_QUEUE_KEY ) == this ) {
933- appContext . put ( AppContext . EVENT_QUEUE_KEY , prevQueue ) ;
916+ if (SunToolkit . currentEventQueue == this ) {
917+ SunToolkit . currentEventQueue = prevQueue ;
934918 }
935919
936920 // Wake up EDT waiting in getNextEvent(), so it can
@@ -1053,7 +1037,7 @@ final boolean isDispatchThreadImpl() {
10531037 final void initDispatchThread () {
10541038 pushPopLock .lock ();
10551039 try {
1056- if (dispatchThread == null && !threadGroup .isDestroyed () && ! appContext . isDisposed () ) {
1040+ if (dispatchThread == null && !threadGroup .isDestroyed ()) {
10571041 EventDispatchThread t = new EventDispatchThread (threadGroup , name , EventQueue .this );
10581042 t .setContextClassLoader (classLoader );
10591043 t .setPriority (Thread .NORM_PRIORITY + 1 );
@@ -1071,7 +1055,7 @@ final void detachDispatchThread(EventDispatchThread edt) {
10711055 /*
10721056 * Minimize discard possibility for non-posted events
10731057 */
1074- SunToolkit .flushPendingEvents (appContext );
1058+ SunToolkit .flushPendingEvents ();
10751059 /*
10761060 * This synchronized block is to secure that the event dispatch
10771061 * thread won't die in the middle of posting a new event to the
@@ -1129,7 +1113,7 @@ final EventDispatchThread getDispatchThread() {
11291113 * {@code removeNotify} method.
11301114 */
11311115 final void removeSourceEvents (Object source , boolean removeAllEvents ) {
1132- SunToolkit .flushPendingEvents (appContext );
1116+ SunToolkit .flushPendingEvents ();
11331117 pushPopLock .lock ();
11341118 try {
11351119 for (int i = 0 ; i < NUM_PRIORITIES ; i ++) {
0 commit comments