결론
wait 와 notify 를 사용할 거면 java.util.concurrent 패키지를 사용하자.
진짜루, wait 랑 notify 랑 notifyAll 을 사용할 일이 거의 없다. 머릿속에서 이 3개가 있다는 걸 지워버리자.
책 번역이 어렵게 되어서, 동시성(concurrent) 과 동기화(synchronization) 가 전혀 다른 말임을 조심하면서 읽자.
발음이 헷갈린다.
동시성(Concurrency) vs 동기화(Synchronization)
- Concurrency: the ability to run several programs or several parts of a program in parallel.
- Synchronization: the coordination of events to operate a system in unison.
요약하자면, concurrency 는 "병렬 시행(Parallel Execution)" 이 핵심이고,
synchronization 은 OS 가 개발자 의도대로 명령을 실행하도록, 실행순서를 "정렬" 하는 작업이 핵심이라 할 수 있겠다.
개념적으로는 그렇고, 일반적으로 자바에서 synchronize 란 Critical Section 에 락을 거는 것을 뜻한다.
java.util.concurrent
- Executor Framework (item80)
- Concurrent Collections
- Synchronizers
Concurrent Collections
- List, Queue, Map 에 concurrency 를 추가
- Concurrent Collection 에게 굳이 락을 추가하지 말자. 느려진다.
- 이펙티브 자바에서 언급된 쓸모있는 collection 들
- ConcurrentMap
- Blocking Queue