stone2083

关于java多线程的几个小贴士

原文地址:
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)


posted on 2010-09-15 17:37 stone2083 阅读(1896) 评论(2)  编辑  收藏

Feedback

# re: 关于java多线程的几个小贴士 2010-09-16 07:54 韩国童装批发

最近在正了解JAVA多线程的东西,搜索到此,留下足迹!!!)|(  回复  更多评论   

# re: 关于java多线程的几个小贴士 2010-09-22 23:45 Princeton

嗯 这几个tips还是挺到位的!  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: