# 1 and # 2 match. You should use the number # 1, since the known part of the API.
If you use # 1 or # 3, it depends on the following:
Is this making changes to the user interface or its swap model? If yes, use # 1.
This is a long-term task: If yes, use # 3.
If this is a long-term task that will ultimately change the user interface or its support model, run the long-term task in a separate thread, and then call incokeLater to update the user interface.
Also, instead of creating a new thread, use the ExecutorService each time so you can reuse the threads.
This can be a little more complicated, for example, if you are currently in the event stream (i.e. in ActionListener.actionPerformed() , then you do not need (as it should not) to invokeLater, but its essence is there.
source share