原文地址:
http://weblogs.java.net/blog/caroljmcdonald/archive/2009/09/17/some-java-concurrency-tips
大綱:
Prefer immutable objects/data
盡可能使用不變對(duì)象/數(shù)據(jù)
Threading risks for Web applications
注意web應(yīng)用的線程安全問(wèn)題
Hold Locks for as short a time as possible
持有鎖的時(shí)間盡可能短
Prefer executors and tasks to threads
盡可能使用JDK并發(fā)工具包提供的Executor框架,進(jìn)行多線程操作
Prefer Concurrency utilities to wait and notify
盡可能使用JDK并發(fā)工具包提供的工具進(jìn)行同步(等待和通知)
- Concurrent Collections
- ConcurrentMap
- ConcurrentHashMap
- COncurrentLinkedQueue
- CopyOnWriteArrayList
- BlockingQueue Implementations
- ArrayBlockingQueue
- LinkedBlockingQueue
- PriorityBlockingQueue
Producer Consumer Pattern
了解生產(chǎn)者消費(fèi)者模式
Synchronizers
同步器
- Semaphore
- CountDownLatch
- CyclicBarrier
- Exchanger
Multithreaded Lazy Initialization is tricky
多線程環(huán)境下,lazy init是一件棘手的事情
Prefer Normal initialization
盡可能使用正常的初始化(盡可能不要使用lazy init)