From cb9880fa8c599587d8f2b852c0615351a73df3ea Mon Sep 17 00:00:00 2001 From: Sergey Shelomentsev Date: Mon, 10 Nov 2025 16:34:29 +0200 Subject: [PATCH] JBR-9610 Set TimerQueue thread exclusion for BugJBR9563.java --- .../jdk/jb/javax/swing/Common/BugJBR9563.java | 43 ++++++++++--------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/test/jdk/jb/javax/swing/Common/BugJBR9563.java b/test/jdk/jb/javax/swing/Common/BugJBR9563.java index 4f735d5394f1..53e39a2a4805 100644 --- a/test/jdk/jb/javax/swing/Common/BugJBR9563.java +++ b/test/jdk/jb/javax/swing/Common/BugJBR9563.java @@ -37,6 +37,7 @@ import java.util.stream.Collectors; @run main BugJBR9563 */ public class BugJBR9563 { + public static void main(String[] args) throws Exception { CountDownLatch windowOpened = new CountDownLatch(1); AtomicReference frameRef = new AtomicReference<>(); @@ -76,24 +77,31 @@ public class BugJBR9563 { Assert(f != null, "Frame is not captured"); - Set threadsAfterRendering = getCurrentThreads(); + Set threadsAfterRendering = getCurrentThreads() + .stream() + .map(t -> t.threadId() + " " + t.getName()) + .collect(Collectors.toSet()); System.out.println("Threads after rendering: " + threadsAfterRendering); - Callable task = () -> { - System.out.println("Check threads state..."); - Set threads = getCurrentThreads(); - List newThreads = threads.stream().filter(it -> !threadsAfterRendering.contains(it)).toList(); - - System.out.println("New threads list: " + newThreads); - return newThreads.isEmpty(); - }; - List results = Collections.synchronizedList(new ArrayList<>()); for (int i = 0; i < 10; i++) { System.out.println("Check threads state..."); - Set threads = getCurrentThreads(); - List newThreads = threads.stream().filter(it -> !threadsAfterRendering.contains(it)).toList(); + List threads = getCurrentThreads(); + List threadsWoTimerQueue = threads + .stream().filter(it -> !it.getName().equals("TimerQueue")).toList(); + + Assert(threads.size() - threadsWoTimerQueue.size() <= 1, "More than 1 TimerQueue thread found"); + + Set threadIdNames = threadsWoTimerQueue + .stream() + .map(t -> t.threadId() + " " + t.getName()) + .collect(Collectors.toSet()); + + List newThreads = threadIdNames + .stream() + .filter(it -> !threadsAfterRendering.contains(it)) + .toList(); System.out.println("New threads list: " + newThreads); @@ -117,14 +125,9 @@ public class BugJBR9563 { } } - private static Set getCurrentThreads() { - Map allThreads = Thread.getAllStackTraces(); - - return allThreads - .keySet() - .stream() - .map(t -> t.threadId() + " " + t.getName()) - .collect(Collectors.toSet()); + private static List getCurrentThreads() { + Map threadsMap = Thread.getAllStackTraces(); + return threadsMap.keySet().stream().toList(); } private static void Assert(boolean condition, String str) {