Questions and Answers from Java

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.