Documentation

The Java™ Tutorials
Hide TOC
Concurrency in SwingSwing中的并发性
Trail: Creating a GUI With Swing

Lesson: Concurrency in Swing教训:Swing中的并发

Examples Index示例索引

This lesson discusses concurrency as it applies to Swing programming. 本课讨论了应用于Swing编程的并发性。It assumes that you are already familiar with the content of the Concurrency lesson in the Essential Java Classes trail.它假设您已经熟悉Essential Java Classes跟踪中Concurrency课程的内容。

Careful use of concurrency is particularly important to the Swing programmer. 谨慎使用并发性对Swing程序员来说尤其重要。A well-written Swing program uses concurrency to create a user interface that never "freezes" — the program is always responsive to user interaction, no matter what it's doing. 一个编写良好的Swing程序使用并发创建一个永不“冻结”的用户界面—程序总是对用户交互做出响应,无论它在做什么。To create a responsive program, the programmer must learn how the Swing framework employs threads.要创建响应程序,程序员必须了解Swing框架如何使用线程。

A Swing programmer deals with the following kinds of threads:Swing程序员处理以下类型的线程:

The programmer does not need to provide code that explicitly creates these threads: they are provided by the runtime or the Swing framework. 程序员不需要提供显式创建这些线程的代码:它们由运行时或Swing框架提供。The programmer's job is to utilize these threads to create a responsive, maintainable Swing program.程序员的工作是利用这些线程创建一个响应迅速、可维护的Swing程序。

Like any other program running on the Java platform, a Swing program can create additional threads and thread pools, using the tools described in the Concurrency lesson. 与Java平台上运行的任何其他程序一样,Swing程序可以使用并发课程中描述的工具创建额外的线程和线程池。But for basic Swing programs the threads described here are sufficient.但对于基本的Swing程序,这里描述的线程就足够了。

This lesson discusses each of the three kinds of threads in turn. 本课依次讨论三种线程中的每一种。Worker threads require the most discussion because tasks that run on them are created using javax.swing.SwingWorker. 工作线程需要最多的讨论,因为在其上运行的任务是使用javax.swing.SwingWorker创建的。This class has many useful features, including communication and coordination between worker thread tasks and the tasks on other threads.这个类有许多有用的特性,包括工作线程任务和其他线程上的任务之间的通信和协调。


Previous page: Previous Lesson
Next page: Initial Threads