Chapter 13: Concurrency
Cheatsheet

Chapter 13 Cheatsheet

How to create threads?

Concurrent classes?

当我们使用 concurrent class 时,是为了解决不同 threads 在不同时间去更改同一个 collection 的 data 而导致 data 不统一的状况,不然就会遇到 ConcurrentModificationException

如果那个 collection 是 immutable 的话,那我们就没必要用到 concurrent class

Threading problems

  1. Deadlock: When two or more threads are blocked forever, each waiting on the other.
  2. Starvation: When a single thread is perpetually denied access to a shared resource or lock.
  3. Livelock: When two or more threads are conceptually blocked forever, although they are each still active and trying to complete their task.