25,985
社区成员
发帖
与我相关
我的任务
分享
public class ManageData {
public static ConcurrentHashMap<SocketAddress,Message> hm =new ConcurrentHashMap<SocketAddress, Message>();
private static byte[] lock= new byte[0];
public void addMessage(SocketAddress client, Message message){
synchronized(lock){
hm.put(client, message);
}
}
public Message getMessageObject(SocketAddress address){
Message ret =null;
ret=hm.get(address);
if(null==ret){
ret=new Message();
synchronized(lock){
hm.put(address, ret);
}
}
return ret;
}
public Message getMessageObject(SocketAddress address){
Message ret =null;
ret=hm.get(address);
if(null==ret){
synchronized(lock){
if((ret=hm.get(address))==null){
ret=new Message();
hm.put(address, ret);
}
}
}
return ret;
}