原文地址:
http://weblogs.java.net/blog/caroljmcdonald/archive/2009/09/17/some-java-concurrency-tips
大纲:
Prefer immutable objects/data
尽可能使用不变对象/数据
Threading risks for Web applications
注意web应用的线程安全问题
Hold Locks for as short a time as possible
持有锁的时间尽可能短
Prefer executors and tasks to threads
尽可能使用JDK并发工具包提供的Executor框架,进行多线程操作
Prefer Concurrency utilities to wait and notify
尽可能使用JDK并发工具包提供的工具进行同步(等待和通知)
- Concurrent Collections
- ConcurrentMap
- ConcurrentHashMap
- COncurrentLinkedQueue
- CopyOnWriteArrayList
- BlockingQueue Implementations
- ArrayBlockingQueue
- LinkedBlockingQueue
- PriorityBlockingQueue
Producer Consumer Pattern
了解生产者消费者模式
Synchronizers
同步器
- Semaphore
- CountDownLatch
- CyclicBarrier
- Exchanger
Multithreaded Lazy Initialization is tricky
多线程环境下,lazy init是一件棘手的事情
Prefer Normal initialization
尽可能使用正常的初始化(尽可能不要使用lazy init)