From 4f2420ae1f9f9da71d4bf3b81de81d8340480feb Mon Sep 17 00:00:00 2001 From: Arno Zeller Date: Tue, 2 Jun 2026 09:44:28 +0200 Subject: [PATCH] Add countdown latch and use while-true loop. --- .../swing/SwingWorker/TestDoneBeforeDoInBackground.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java b/test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java index 56534928f6e..05de0a4566d 100644 --- a/test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java +++ b/test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java @@ -43,13 +43,15 @@ public class TestDoneBeforeDoInBackground { private static final AtomicBoolean doInBackgroundFinished = new AtomicBoolean(false); private static final AtomicBoolean doneFinished = new AtomicBoolean(false); private static final CountDownLatch doneLatch = new CountDownLatch(1); + private static final CountDownLatch workerStarted = new CountDownLatch(1); public static void main(String[] args) throws InterruptedException { SwingWorker worker = new SwingWorker<>() { @Override protected String doInBackground() throws Exception { try { - while (!Thread.currentThread().isInterrupted()) { + while (true) { + workerStarted.countDown(); System.out.println("Working..."); Thread.sleep(WAIT_TIME); } @@ -121,7 +123,7 @@ public class TestDoneBeforeDoInBackground { } }); worker.execute(); - Thread.sleep(WAIT_TIME * 3); + workerStarted.await(); final long start = System.currentTimeMillis(); worker.cancel(true);