Starvation and Livelock<译>

November 17, 2022 作者: yijianhao 分类: jdk文档翻译 浏览: 147 评论: 0

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.

例如,假设有一个对象执行了一个需要很长时间才能返回的synchronized方法

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 reonsspe to the action of another thread, then livelock may result.

一个线程通常响应另一个线程的操作。如果其他线程的操作也是另一个线程操作的重新执行,则可能会导致Livelock的发生

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…

这就好比两个人试图在走廊里面相互追逐,Alphonse跑向他的左边想让Gaston能过去,而Gaston跑向他的右边去想让Alphonse能过去。看得出来他们仍在妨碍着对方,Alphone跑到他的右边,而Gaston又跑到了他的左边。他们依旧彼此妨碍,所有。。。(这个比喻有点难看懂呢)

#概念(3)

评论