These two methods in SwingWorker are confusing me at the moment, and it seems like it is very easy to use them incorrectly.
The method publish() describes the following:
Sends data chunks to the process(java.util.List) method. This method is to be used from inside the doInBackground method to deliver intermediate results for processing on the Event Dispatch Thread inside the process method.
What this means to me is that while my worker thread is executing its doInBackground() method, I am able to create "chunks" (should these be anything specific or is this just a way to refer to message objects?), then publish them for processing on my Swing GUI.
That leads me to process(). The javadoc outlines the following:
Receives data chunks from the publish method asynchronously on the Event Dispatch Thread.
Having looked over the documentation for both methods, could anybody clarify what the mechanism is behind how this is taking place? I understand that it is an asynchronous process as per the documentation but since it is taking place on the EDT I am picturing there being some predictability to it.
The publish()
documentation states this:
Because the process method is invoked asynchronously on the Event Dispatch Thread multiple invocations to the publish method might occur before the process method is executed. For performance purposes all these invocations are coalesced into one invocation with concatenated arguments.
To summarize, my question is two fold:
- Who should be calling
process()
? - What is the workflow for
process()
in the context of the SwingWorker and the EDT?
Please let me know if any clarification is needed.