About Me

我的相片
Mr. Pigg
Taipei, Taiwan
檢視我的完整簡介

星期一, 8月 11, 2008

Effective Java - Chapter 10 Concurrency

  1. Use Synchronize access to shared mutable data
    - synchronize除了用來防止同時更改資料,也是用來保證會讀取到最新資料
    - synchronize要設在get與update
    - volatile
  2. 不要過度使用Synchronize
    - alien => 只synchronize必要的部份, synchoronize越少越好 open call
    - 使用CopyOnWriteArrayList/Set
    - 讓client決定是否synchronize, 除非你自己有把握做的更好
    - static field一定要synchronize
  3. Prefer executors
    - ExecutorService提供許多好用的機制
  4. Prefer concurrency utilities to wait and notify
    - ExecutorService
    - Concurrent collections
    - CountDownLatch / Semaphore, CyclicBarrier / Exchanger
    - The standard idiom for using the wait method
    - Private lock object idiom
  5. Any program that relies on the
    thread scheduler for correctness or performance is likely to be nonportable
  6. thread groups are obsolete

0 意見: