【翻译十三】java-并发之饥饿与活锁

Starvation and Livelock

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

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.

Livelock

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…

译文:

饥饿与活锁

饥饿和活锁比死锁要出现的少,但是对于每个设计并发软件的人也是经常遇到的问题。

饥饿

饥饿描述了一个线程由于得不到足够的资源而不能执行程序的现象。这种情况发生时,共享资源不能由一个“贪婪”的线程长时间占用。例如,假设一个对象有一个同步的方法,需要很长时间才能返回。如果一个线程经常执行这个方法,其他需要同样访问这个资源的线程就有可能出现阻塞的情况。

活锁

一个线程经常需要另外一个线程的支持。如果其他一个线程的动作也响应另外一个线程的动作,那么活锁就有可能发生。就像死锁一样,活锁线程也不能使程序继续执行。然而,这些线程并没有阻塞-他们只是要互相请求从而导致非常的繁忙。这就像两个人在走廊里互相传递东西一样:Alpthose 把他左手的东西传递给Gaston,而Gaston把他右手的东西又传递给Alpthose.看到这些,他们实际上也是互相在阻塞对方,Alphone移到他的右边,而Gaston移到他的左边。他们依旧在互相阻塞,因此……。

 

 

    原文作者:alexander.bruce.lee
    原文地址: http://www.cnblogs.com/accipiter/p/3235711.html
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞