RFR: 8081474: SwingWorker calls 'done' before the 'doInBackground' is finished [v3]

Prasanta Sadhukhan psadhukhan at openjdk.org
Tue Jan 31 08:54:39 UTC 2023


On Tue, 31 Jan 2023 05:56:24 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> Yet having `sleep` is an indication of busy wait. You could've used `CountDownLatch` in conjunction with `setState` to avoid `sleep` at all.
>> 
>>> I removed sleep from EDT case and not blocking EDT and guess sleep is now being done for non-EDT case...
>> 
>> Ah, right. But then if `cancel` is called on EDT, `done` is invoked before `doInBackground` completes, isn't it?
>> 
>> If `cancel` is called from another thread, the main thread as in the test, it doesn't return until `doInBackground` completes. With your test case and fix, `cancel` blocks for 5 seconds.
>> 
>> Either way, the behaviour does not look right.
>
> It seems the isDone method modification is causing a JCK test to fail and there's no spec for it to challenge JCK test, although logically it seems right that STATE should be DONE but for now, I have modified the fix which satisfies regression test and JCK both..

isDone() spec mention `"Completion may be due to normal termination, an exception, or cancellation -- in all of these cases, this method will return true"`
so for cancel state also, the state needs to be in DONE state, in which case we can reinstate the DONE state check in isDone()

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

PR: https://git.openjdk.org/jdk/pull/11940



More information about the client-libs-dev mailing list