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

Alexey Ivanov aivanov at openjdk.org
Thu Feb 9 20:26:50 UTC 2023


On Wed, 8 Feb 2023 01:22:52 GMT, Sergey Bylokhov <serb at openjdk.org> 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?

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.

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

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



More information about the client-libs-dev mailing list