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-并发之饥饿与活锁的更多相关文章

  1. Java并发之CyclicBarria的使用

    Java并发之CyclicBarria的使用 一.简介 笔者在写CountDownLatch这个类的时候,看到了博客园上的<浅析Java中CountDownLatch用法>这篇博文,为博主 ...

  2. 关于 调用 JNI JAR 的说明和注意事项,调用第三方 JAR SDK 和 翻译 安卓 JAVA 代码 的说明 V2015.6.10

    关于 调用 JNI JAR 的说明和注意事项,调用第三方 JAR SDK 和 翻译 安卓 JAVA 代码 的说明 V2015.6.10 转载请标明出处,否则死全家.选择[复制链接]即可得到出处. (* ...

  3. java并发之固定对象与实例

    java并发之固定对象与实例 Immutable Objects An object is considered immutable if its state cannot change after ...

  4. Java并发之BlockingQueue的使用

    Java并发之BlockingQueue的使用 一.简介 前段时间看到有些朋友在网上发了一道面试题,题目的大意就是:有两个线程A,B,  A线程每200ms就生成一个[0,100]之间的随机数, B线 ...

  5. JUnit单元测试教程(翻译自Java Code Geeks)

    JUnit单元测试教程--终极指南 JUnit单元测试教程终极指南 说明 单元测试简介 1 什么是单元测试 2 测试覆盖 3 Java中的单元测试 JUnit简介 1 使用Eclipse实现简单JUn ...

  6. 深入理解Java并发之synchronized实现原理

    深入理解Java类型信息(Class对象)与反射机制 深入理解Java枚举类型(enum) 深入理解Java注解类型(@Annotation) 深入理解Java类加载器(ClassLoader) 深入 ...

  7. Java并发之Semaphore的使用

    Java并发之Semaphore的使用 一.简介 今天突然发现,看着自己喜欢的球队发挥如此的棒,然后写着博客,这种感觉很爽.现在是半场时间,就趁着这个时间的空隙,说说Java并发包中另外一个重量级的类 ...

  8. Java并发之CyclicBarria的使用(二)

    Java并发之CyclicBarria的使用(二) 一.简介 之前借助于其他大神写过一篇关于CyclicBarria用法的博文,但是内心总是感觉丝丝的愧疚,因为笔者喜欢原创,而不喜欢去转载一些其他的文 ...

  9. Java并发之CountDownLatch的使用

    Java并发之CountDownLatch的使用 一. 简介 Java的并发包早在JDK5这个版本中就已经推出,而且Java的并发编程是几乎每个Java程序员都无法绕开的屏障.笔者今晚在家闲来无事,翻 ...

随机推荐

  1. Android权限 uses-permission

    Manifest.permission 官方API说明: http://developer.android.com/reference/android/Manifest.permission.html ...

  2. Linux 查看磁盘空间大小

    (1)查看文件大小 1. 查看当前文件夹下所有文件大小(包括子文件夹)    du -sh   2.查看var目录下文件大小   du -sh var   3.查看指定文件夹下所有文件大小(包括子文件 ...

  3. 浏览器js自动查表脚本

    javascript: void((function() {$.get("", {wen: "880350384879600241",action: " ...

  4. EXT Grid celleditor列编辑,动态控制某一单元格只读

    listeners : { beforeedit:function(editor, context, eOpts) { if(context.record.data.hasRatio == " ...

  5. devstack两次以上重装提高成功率的方法

    1) /opt/stack/requirements/ git reset --hard 2) rm -rf /usr/local/lib/python2.7/dist-packages/*

  6. Codeanywhere

    停用了一个,试一试这个怎么样. 网速太慢了,还在摸索中,没有放弃这个. 备选为Cloud9

  7. poj 2378 (dijkstra)

    http://poj.org/problem?id=2387 一个dijkstra的模板题 #include <stdio.h> #include <string.h> #de ...

  8. 饿了么 openapi demo

    http://merchant.openapi.eleme.io/merchant.html#id215 class Program { static void Main(string[] args) ...

  9. Xcode 必备插件管理器 http://alcatraz.io

    各种小插件,其中写注释用的 VVDocumenter 是必备的!

  10. 2.nodejs权威指南--Buffer

    1. Buffer 1.1 创建 var buf1 = new Buffer(100); var buf2 = new Buffer([0,1,2]); var buf3 = new Buffer(' ...