On Tue, 9 Jun 2026 10:25:00 GMT, Arno Zeller <[email protected]> wrote:

>> The doInBackground working loop is left because of the loop condition 
>> (!Thread.currentThread().isInterrupted()) - this will not clear the 
>> interrupted status of the thread and the Thread.sleep at line 63 will throw 
>> an InterruptedException directly.
>> I suggest to change two things:
>> No longer check the !Thread.currentThread().isInterrupted() but rely only on 
>> the Thread.sleep to throw an InterrutedException.
>> And using a countdown latch instead of a sleep to ensure that we really 
>> entered the loop before we do cancel the worker.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Arno Zeller has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Add timeout to CountDownLatch and use Utils.adjustTimeout.

Changes requested by aivanov (Reviewer).

@mrserb Could you take a look as a reviewer of the original fix? #11940

@prsadhuk, as the author of that fix, should also review this fix.

test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java line 42:

> 40: public class TestDoneBeforeDoInBackground {
> 41: 
> 42:     private static final int WAIT_TIME = (int)Utils.adjustTimeout(200);

Suggestion:

    private static final long WAIT_TIME = Utils.adjustTimeout(200);

I'd rather use `long` directly. It would also align with `CLEANUP_TIME` that 
uses `long`.

test/jdk/javax/swing/SwingWorker/TestDoneBeforeDoInBackground.java line 57:

> 55:                 try {
> 56:                     while (true) {
> 57:                         workerStarted.countDown();

Why not call `workerStarted.countDown()` before the loop starts? It should be a 
one-time thing rather than a repeated action.

-------------

PR Review: https://git.openjdk.org/jdk/pull/31348#pullrequestreview-4458909801
PR Comment: https://git.openjdk.org/jdk/pull/31348#issuecomment-4660342551
PR Review Comment: https://git.openjdk.org/jdk/pull/31348#discussion_r3381044219
PR Review Comment: https://git.openjdk.org/jdk/pull/31348#discussion_r3380889634

Reply via email to