On Thu, 9 Feb 2023 20:24:18 GMT, Alexey Ivanov <[email protected]> wrote:

>>> 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.
>> 
>> Which parts are contradicts? I mean that the old implementation call 
>> DONE-listener last, as specified in the header of the class what part of the 
>> spec mention different behavior? Above we discussed that it is possible to 
>> see a difference if the listener will do some work on EDT, after the fix the 
>> listener will not be called last, is that safe to assume it does not break 
>> something?
>
>> > 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.
>> 
>> Which parts are contradicts?
> 
> This was a wrong statement. In fact, I referred to the problem that is being 
> fixed here: `done` may be called before `doInBackground`.
> 
> https://github.com/openjdk/jdk/blob/0aeebee284effe9abd0ed3cf2845430b40bb53bd/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L288-L293
> 
> The spec for `DONE` state does not specify when the transition occurs.
> 
>> I mean that the old implementation call DONE-listener last, as specified in 
>> the header of the class what part of the spec mention different behavior?
> 
> Yes, this is how it's specified now.
> 
>> Above we discussed that it is possible to see a difference if the listener 
>> will do some work on EDT, after the fix the listener will not be called 
>> last, is that safe to assume it does not break something?
> 
> What kind of difference? Yes, you can observe the fact that now the 
> `DONE`-state-listener is called before the `done` method.
> 
> In either case, the listener and the method are called when `get` does not 
> block. The background job is finished when either of these events occurs.
> 
> I see no problem here.

> > It could be tested by flushing and blocking the EDT in the listener. That 
> > will allow us to check the order of events posted from the listener and 
> > from the "doneEDT".
> 
> Is flushing required?
> 
> Two `AtomicBoolean`s should do the job.

I referred to `isStateDoneNotified` and `isDoneCalled`.

> EDT can't process two events simultaneously, one follows the other. So, 
> `done` is expected to be called while both are `false`, and it sets its own 
> flag to `true`; the listener should be called second, so its flag is `false` 
> and `done`'s flag is `true`.

Do we want to ensure it?

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

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

Reply via email to