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发行说明。
Starvation and livelock are much less common a problem than deadlock, but are still problems that every designer of concurrent software is likely to encounter.饥饿和活锁比死锁更不常见,但仍然是每个并发软件设计者可能遇到的问题。
Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. 饥饿描述了线程无法定期访问共享资源并且无法取得进展的情况。This happens when shared resources are made unavailable for long periods by "greedy" threads. 当“贪婪”线程使共享资源长时间不可用时,就会发生这种情况。For example, suppose an object provides a synchronized method that often takes a long time to return. 例如,假设一个对象提供了一个通常需要很长时间才能返回的同步方法。If one thread invokes this method frequently, other threads that also need frequent synchronized access to the same object will often be blocked.如果一个线程频繁调用此方法,那么也需要频繁同步访问同一对象的其他线程通常会被阻塞。
A thread often acts in response to the action of another thread. 一个线程经常响应另一个线程的操作。If the other thread's action is also a response to the action of another thread, then livelock may result. 如果另一个线程的操作也是对另一个线程的操作的响应,那么可能会产生活锁。As with deadlock, livelocked threads are unable to make further progress. 与死锁一样,活锁线程无法取得进一步的进展。However, the threads are not blocked they are simply too busy responding to each other to resume work. 但是,线程没有阻塞他们只是忙着互相回复,无法继续工作。This is comparable to two people attempting to pass each other in a corridor: Alphonse moves to his left to let Gaston pass, while Gaston moves to his right to let Alphonse pass. 这相当于两个人试图在走廊里互相超越:阿尔方斯向左移动让加斯顿通过,而加斯顿向右移动让阿尔方斯通过。Seeing that they are still blocking each other, Alphone moves to his right, while Gaston moves to his left. 看到他们仍在互相阻挡,阿尔方斯移到了他的右边,而加斯顿移到了他的左边。They're still blocking each other, so...他们还在互相阻拦,所以……