Programming Concurrency on the JVM - Venkat Subramaniam

Programming Concurrency on the JVM

Venkat Subramaniam

出版时间

2011-06-01

ISBN

9781934356760

评分

★★★★★
书籍介绍
Concurrency on the Java platform has evolved, from the synchronization model of JDK to software transactional memory (STM) and actor-based concurrency. This book is the first to show you all these concurrency styles so you can compare and choose what works best for your applications. You’ll learn the benefits of each of these models, when and how to use them, and what their limitations are. Through hands-on exercises, you’ll learn how to avoid shared mutable state and how to write good, elegant, explicit synchronization-free programs so you can create easy and safe concurrent applications. The techniques you learn in this book will take you from dreading concurrency to mastering and enjoying it. Best of all, you can work with Java or a JVM language of your choice – Clojure, JRuby, Groovy, or Scala – to reap the growing power of multicore hardware. If you are a Java programmer, you’d need JDK 1.5 or later and the Akka 1.0 library. In addition, if you program in Scala, Clojure, Groovy or JRuby you’d need the latest version of your preferred language. Groovy programmers will also need GPars.
AI导读
核心看点
  • 系统对比共享可变、隔离可变与不可变三种并发模型
  • 深入解析STM软件事务内存与Actor并发模式
  • 提供Java、Clojure、Scala等多语言实战示例
适合谁读
  • 希望拓展并发视野的Java及JVM语言开发者
  • 对STM或Actor模型感兴趣的进阶程序员
  • 寻求解决复杂并发问题的后端工程师
读前提醒
  • 部分代码示例较旧,建议结合官方文档对照阅读
  • 书中Scala篇幅较多,非Scala用户可酌情跳过
  • 实例偏理论演示,复杂业务场景需自行推导
读者共识
  • 言简意赅,是入门STM和Actor模型的优质读物
  • 有效打破传统锁思维,拓宽并发编程视野
  • 部分技术已过时,适合略读以建立概念框架

本导读基于书籍简介、目录、原文摘录、短评和书评生成,不等同于全文精读。

精彩摘录
  • "在那些没有强制不变性的语言中,我们必须人工保证消息都是不可变的。 某些 Actor 的意外失败有可能导致其它 Actor 饿死,一个或多个 Actor 可能会一直等待某些关键的协作消息,而这些消息有可能由于本应发出该消息的 Actor 失败而永远无法抵达。因此,我们需要谨慎编码,在 Actor 中加入异常情况的处理逻辑,并将错误消息传播给那些等待响应的 Actor。 当两个或多个 Actor 互相等待对方发来的消息时,所有的 Actor 都将陷入死锁。我们应该使用超时来保证程序不会由于协调环节中各别 Actor 的无法响应而导致其它 Actor 无限期的等待。 只有在待解决的任务可以被拆分成多"
  • "一方面,我们绝不应该在构造函数中启动线程;而另一方面,我们也不愿意在对象没有完全创建好之前就启动它。 解决方案就是在 《Effective Java》一书的第一项中:“考虑使用静态工厂函数来代替构造函数”。即在一个静态工厂函数中创建对象实例,并在将实例的引用返回给调用方之前启动线程。 我们绝对不要访问一个处于无效状态中的对象。"
  • "Shared mutability is pure evil, avoid it."
  • "By default, Java runs in client mode on 32-bit Windows and in server mode on the Mac."
  • "Number of threads = Number of Available Cores / (1 - Blocking Coefficient) where the blocking coefficient is between 0 and 1. A computation-intensive task has a blocking coefficient of 0, whereas an IO-intensive task has a value close to 1"
  • "The newer generation of concurrency APIs in the java.util.concurrent package, spear-headed by Doug Lea, among others, has nicely replaced the old threading API. • Wherever we use the Thread class and its methods, we can now rely upon the ExecutorService class and related classes. • If we need better"
  • "To achieve the maximum speedup, we need to partition the problem across the two threads evenly."
  • "While Bagwell’s tries were not immutable, Rich Hickey, the creator of Clojure, used a variation of them to create a persistent hash implementation in Clojure."
作者简介
Dr. Venkat Subramaniam is an award-winning author, founder of Agile Developer, Inc., and an adjunct faculty at the University of Houston. He has trained and mentored thousands of software developers in the US, Canada, Europe, and Asia, and is a regularly-invited speaker at several international conferences.
用户评论
concurrency practice on the jvm (Clojure, Java, JRuby, Scala)
介绍了 JVM 语言中并发的模式与利弊,这对开拓眼界是非常有用的,书中给出的算文件夹大小的例子也不错,由浅入深,逐步完善。
看了一点,不怎么喜欢就放一边了
介绍了一些比较新的并发技术,如STM、Actor等,并进行举例
可以了解一下STM和Actor模式,但是书一直执着地用Closure和Scala,JRuby做例子,能否提升到更高的层次。在STM部分,我看到的更多的是对Closure语言封装性的介绍,dosync如何如何好,如何如何不需要费神。大哥你确定自己不是在写hibernate的使用手册吧。
花了太多篇幅去讲STM和Actors
收藏