1 . What are worker threads and SwingWorker and how do I use them?
When a swing program needs to perform a long task, it is usually done using a worker thread. Each task executes in a worker thread, which is an instance of the Javax.swing.SwingWorker class. The SwingWorker class is an abstract class; You must define its subclasses to create a SwingWorker object, which is usually done using anonymous inner classes. SwingWorker provides some features of communication and control: [1]swingworker subclasses can define a method, done. When the background task is completed, it is automatically called by the event dispatch thread. [2] The SwingWorker class implements Java.util.concurrent.Future. This interface allows the background task to provide a return value to other threads. The methods in this interface also provide the ability to allow background tasks to be undone and to determine whether a background task is completed or revoked. [3] A background task can provide intermediate results by calling Swingworker.publish, which is called by the event dispatch thread. [4] Background tasks can define binding properties. The change in the binding property will trigger the event, and the event dispatch thread will invoke the event handler to handle these triggered events.
Questions and Answers from Java