From aba5d31ae73c9ffc9f7f9ab192f91e7e33f5bc66 Mon Sep 17 00:00:00 2001 From: Phil Race Date: Sun, 22 Mar 2026 19:51:45 +0000 Subject: [PATCH] 8378605: Remove AppContext from the Swing TimerQueue implementation Reviewed-by: psadhukhan, dnguyen --- .../share/classes/javax/swing/TimerQueue.java | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/java.desktop/share/classes/javax/swing/TimerQueue.java b/src/java.desktop/share/classes/javax/swing/TimerQueue.java index 4ef2769652a..39c06e57479 100644 --- a/src/java.desktop/share/classes/javax/swing/TimerQueue.java +++ b/src/java.desktop/share/classes/javax/swing/TimerQueue.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2026, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,7 +28,7 @@ package javax.swing; import java.util.concurrent.*; import java.util.concurrent.locks.*; import java.util.concurrent.atomic.AtomicLong; -import sun.awt.AppContext; +import sun.awt.util.ThreadGroupUtils; /** * Internal class to manage all Timers using one thread. @@ -40,8 +40,7 @@ import sun.awt.AppContext; */ class TimerQueue implements Runnable { - private static final Object sharedInstanceKey = - new StringBuffer("TimerQueue.sharedInstanceKey"); + private static volatile TimerQueue sharedInstance; private final DelayQueue queue; private volatile boolean running; @@ -69,14 +68,10 @@ class TimerQueue implements Runnable public static TimerQueue sharedInstance() { synchronized (classLock) { - TimerQueue sharedInst = (TimerQueue) - SwingUtilities.appContextGet( - sharedInstanceKey); - if (sharedInst == null) { - sharedInst = new TimerQueue(); - SwingUtilities.appContextPut(sharedInstanceKey, sharedInst); + if (sharedInstance == null) { + sharedInstance = new TimerQueue(); } - return sharedInst; + return sharedInstance; } } @@ -88,9 +83,10 @@ class TimerQueue implements Runnable return; } try { - final ThreadGroup threadGroup = AppContext.getAppContext().getThreadGroup(); + final ThreadGroup threadGroup = ThreadGroupUtils.getRootThreadGroup(); String name = "TimerQueue"; Thread timerThread = new Thread(threadGroup, this, name, 0, false); + timerThread.setContextClassLoader(null); timerThread.setDaemon(true); timerThread.setPriority(Thread.NORM_PRIORITY); timerThread.start(); @@ -183,11 +179,6 @@ class TimerQueue implements Runnable timer.getLock().unlock(); } } catch (InterruptedException ie) { - // Shouldn't ignore InterruptedExceptions here, so AppContext - // is disposed gracefully, see 6799345 for details - if (AppContext.getAppContext().isDisposed()) { - break; - } } } } finally {