On Fri, 3 Feb 2023 12:31:08 GMT, Prasanta Sadhukhan <[email protected]> 
wrote:

>>> It seems the order of sequence is 
>>> listener->State.STARTED->doInBackground->listener->DONE->done
>> 
>> Yes, but the different order is specified: listener(STARTED) -> 
>> doInBackground -> done -> listener(DONE).
>
> But then it will violate
> https://github.com/openjdk/jdk/blob/810c8a271b4524ae776e2306ef699e04a7d145a2/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L288-L293

Hm… not really, state will transition to `DONE` after `doInBackground` is 
finished.

In fact, it'll happen soon enough: `doneEDT` will schedule execution of `done` 
on EDT and exit. Then the state will change to `DONE`. Yet listeners are 
notified on EDT, to this notification will also be scheduled to run on EDT.

Very much likely that the state is `DONE` when `done` is executed but it's not 
guaranteed.

---

The specification isn't clear, and some parts somewhat contradict each other. 
Logically, the state should transition to `DONE` as soon as `doInBackground` 
completes. Then both `done` method and listeners are called when the state is 
`DONE` that is *the background work is complete*.

Yet as it's specified now, the `done` method is called while the state is still 
`STARTED`. This kind of implies calling `get` may block because the result of 
computation may not be available yet. However, it's not the case: `get` never 
blocks if called from `done`: it either returns the result or throws 
`CancellationException`.

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

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

Reply via email to