On Thu, 2 Feb 2023 21:28:57 GMT, Alexey Ivanov <[email protected]> wrote:

>> 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".
>
> I haven't verified it, but I think it worked as it's stated: `done` is called 
> first, then listeners are notified. According to the order of calls
> 
> https://github.com/openjdk/jdk/blob/b00b70c2400d28070d26630614a010bc52237827/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L310-L313
> 
> `SwingWorker.done` gets invoked first followed by `setState` which, in its 
> turn, notifies the listeners.
> 
> At this time, as you pointed out, the order is reversed:
> 
> https://github.com/openjdk/jdk/blob/76b02ea3a8add954705d6df7f91f5896d141b02d/src/java.desktop/share/classes/javax/swing/SwingWorker.java#L307-L308

> 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. 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`.

I'll leave it to Pransanta to figure out the details.

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

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

Reply via email to