SwingUtilities 和SwingWorker
SwingWorker?is used for the following purposes:
done()?method.publish()?and?process()?methods.SwingUtilities.invokeLater()?can perform the above tasks as follows:
SwingWorker.execute()?method from the EDT, we can executeExecutorService.submit(new MyRunnable())?as it will also create another thread which can execute long-running task.done()?method of case1)SwingUtilites.invokeLater(new RunnableToExecuteDoneMethodCode())?at the end of the task.process()?method of case1)SwingUtilites.invokeLater(new RunnableToExecuteProcessMethodCode())?at the place where we called?publish()?method in case1.It looks like you would want to:
use?SwingWorker?when you need to monitor the status of a long-running background process
use?SwingUtilities.invokeLater?if you just want a short task to run but do not need feedback on it. Sort of like a fire-and-forget. Just keep in mind it will run in the AWT event dispatching thread, so your application would not be getting any events handled while the task is running.