I have a SwingWorker, which does some computations in the background (these actions are situated in the overridden doInBackground() method). So, I also use the execute() method to begin the computations. How I can get the result of these computations when they are finished?
I have a SwingWorker, which does some computations in the background (these actions are
Share
Override the
donemethod – that method will be called when the work is complete. Oracle has a comprehensive tutorial here: Improve Application Performance With SwingWorker in Java SE 6Also see another SO question: How do I use SwingWorker in Java?
You can call
getto retrieve the results but if the worker isn’t done the thread will block until the worker is done. That means if you callgetfrom the Event Dispatch Thread (EDT) your GUI will be unresponsive if the worker isn’t done. You can callisDoneto determine if the worker has completed.Finally, you can attach a property change listener to be notified of the worker’s progress, including when it completes its task. The first link I posted gives an example of that.