我想知道我的缓存实现是否正确,并希望得到任何反馈。资源具有一些分配的字符串(客户端 - 地址)值。
我是否必须同步addEntityRegistration()方法?或者这个用例有更好的方法吗?
提前谢谢, 米@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class Cache{
private Map<Object, Set<String>> registeredClients = new ConcurrentHashMap<Object,Set<String>>();
.....
protected void addEntityRegistration(Object key, String fullJid){
Set<String> registered = registeredClients.get(key);
if(registered == null){
registered = Collections.newSetFromMap(new ConcurrentHashMap<String,Boolean>());
registeredClients.put(key, registered);
}
registered.add(fullJid);
}