Here's what the documentation for SwingWorker says:
- doInBackground()
executes in a worker thread
- process()
executes asynchronously on the Event Dispatch thread (AWT EDT). It's execution is unpredictable with respect to calls to publish()
in the worker thread
- done()
executes in the AWT EDT after doInBackground()
has completed
I cannot see anything that says the last invocation of process()
is always executed before done()
(they both run on the same thread).
I have multiple calls to publish()
from doInBackground()
; the published objects are picked up in process()
and used to update a GUI with progress reports. A literal interpretation of the documentation could imply that it's possible for done()
to be scheduled on the EDT before the very last execution of process()
, because done()
is guaranteed to execute after the worker thread but process()
is documented as being unpredictable.
All my tests show that done()
runs after the last publish()
(which makes sense, and it's what I want), but has anyone seen documentation or dug into the code to verify if SwingWorker is designed to guarantee that behaviour?
the answer is no. See DSquare's answer linked to below.
publish()
doesn't directly scheduleprocess
, it sets a timer which will fire the scheduling of aprocess()
block in theEDT
afterDELAY
.