The Java Tutorials have been written for JDK 8.Java教程是为JDK 8编写的。Examples and practices described in this page don't take advantage of improvements introduced in later releases and might use technology no longer available.本页中描述的示例和实践没有利用后续版本中引入的改进,并且可能使用不再可用的技术。See Java Language Changes for a summary of updated language features in Java SE 9 and subsequent releases.有关Java SE 9及其后续版本中更新的语言特性的摘要,请参阅Java语言更改。
See JDK Release Notes for information about new features, enhancements, and removed or deprecated options for all JDK releases.有关所有JDK版本的新功能、增强功能以及已删除或不推荐的选项的信息,请参阅JDK发行说明。
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.这个类有许多有用的特性,包括工作线程任务和其他线程上的任务之间的通信和协调。