• 【翻译十三】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移到他的左边。他们依旧在互相阻塞,因此……。

    简历: 三年国内著名软件公司Java信息系统开发经验。熟悉税务相关业务知识。一年以上互联网公司工作经验。 目标职位: Java研发工程师、大数据、推荐算法等。 目标城市: 北京,杭州,沈阳。 联系方式: 邮箱:hecuking@126.com
  • 相关阅读:
    AcWing 199. 余数之和
    AcWing 295. 清理班次
    AcWing 294. 计算重复
    Acwing 393. 雇佣收银员
    AcWing 362. 区间
    AcWing 361. 观光奶牛
    CSP-S 2019 Emiya 家今天的饭
    CSP-S 2019游记
    AcWing 345. 牛站 Cow Relays
    java 环境配置
  • 原文地址:https://www.cnblogs.com/accipiter/p/3235711.html
Copyright © 2020-2023  润新知