What is "swingworker"
The SwingWorker
is an abstract Java class that abstracts developer threading complexities into Swing applications.
The class SwingWorker
is very useful in modeling tasks that have to do time-consuming work (in the background) that should not stop the graphical interface while being performed. As an example of typical time-consuming work to be performed with the SwingWorker
, we have operations in files, in network, in databases and operations that consume enough computational resource.
TO EDT (Event-Dispatch-thread) is the thread on which AWT and Swing are executed. If these operations are performed within the EDT, the AWT and Swing are "frozen", because the thread that should be taking care of them remains busy performing other people’s work that can block it.
With the use of threads, it is possible to separate the work to be done in background of the work to be carried out in the EDT, so as not to carry out time-consuming and blocking operations in the EDT and keep the user interface responsive. However, the direct use of threads for this purpose is a complicated task, and higher-level abstractions that already readily provide adequate separation already properly organized make it useful, and that is where the class SwingWorker
appears.
The class SwingWorker
also offers cancellation and update functionality of work progress done on background.
For more information visit: