【发布时间】:2021-07-01 18:57:31
【问题描述】:
我需要一个线程安全映射,我有这样的东西:(我对 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
}
}
【问题讨论】:
-
注意,可变静态是一个非常非常非常糟糕的主意。
-
一个simple主题介绍...
标签: java