一块积木

系统是积木堆起来的,软件是积木堆起来的,世界也是积木堆起来的

用户操作
[留言]  [发消息]  [加为好友] 
订阅我的博客
XML聚合    FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
goodboy1881的公告
<p style="color:blue;font-size:90%;">知其然,不知其所以然,不如不知。 </p> <h3>最近动向</h3> <p style="color:blue;font-size:90%;"> 开始研究tomcat服务器。开始自己的J2EE历程 </p> <h3>个人简介</h3> <p style="color:blue;font-size:90%;">学习口味甚杂, linux, solaris FreeBSD都有涉猎。 C++玩儿了4年,Java玩儿了一年。 其他网页脚本语言玩儿了两个月。 欢迎交流。</p> <h3>我的联系方式</h3> <p style="color:blue;font-size:90%;"> 邮件:goodboy1881(at)gmail.com</p> <h3>rss订阅</h3> <p><a href="http://www.gougou.com/2D9285GI" title="用狗狗订阅"><img src="http://www.gougou.com/count/G/I/2D9285GI.png" border="0" /></a></p>
文章分类
给我留言
给我留言
推荐阅读
Boost Getting Started 安装文档(翻译1.33版本)
饼子堂
一起在道上混的
不亦快斋(RSS)
废人废语(RSS)
存档

转载  Making a Thread-Safe or Synchronized Collection 收藏

 
Making a Thread-Safe or Synchronized Collection

As you know by now, the commonly used collection classes, such as java.util.ArrayList, are not synchronized. However, if there's a chance that two threads could be altering a collection concurrently, you can generate a synchronized collection from it using the synchronizedCollection() method. Similar to the read-only methods, the thread-safe APIs let you generate a synchronized collection, list, set, or map. For instance, this is how you can generate a synchronized map from a HashMap:
 
Map map = Collections.synchronizedMap(new HashMap());
map.put(“key”, “result”);

Note that the reference is not stored to the un-synchronized map. It's very important to only access a synchronized collection or a map from the object (reference) returned by the corresponding synchronizeXXX() method. Otherwise, the behavior would be undefined.

发表于 @ 2006年07月12日 16:39:00 | 评论( loading... ) | 编辑| 举报| 收藏

旧一篇:2006年高考作文爆笑集锦 | 新一篇:数据库系统概念读书笔记(2)--实体联系模型

  • 发表评论
  • 评论内容:
  •  
Copyright © goodboy1881
Powered by CSDN Blog