我需要一个线程安全的地图,我有这样的东西:(我对java很新)
public static class Manager
{
static
{
//something wrong here, doesn't compile
list = new java.util.Collections
.synchronizedMap(new Map<String, Client>());
}
static Map<String,Client> list;
public static void AddClient(Client client)
{
// thread safe add client to the list
}
public static void RemoveClient(Client client)
{
// thread safe remove client to the list
}
}
Run Code Online (Sandbox Code Playgroud)
Boz*_*zho 95
java.util.concurrent.ConcurrentHashMap
Pas*_*ent 33
包中的ConcurrentHashMap类java.util.concurrent是Map的线程安全实现,它提供了比synchronizedMap(并且具有更高的可伸缩性Hashtable)更好的并发性.请访问http://www.ibm.com/developerworks/java/library/j-jtp07233.html.
| 归档时间: |
|
| 查看次数: |
65858 次 |
| 最近记录: |