下面是我声明的函数。当我从客户端获取一个xmpp节时,只调用此函数。如果我的条件满足,那么我将一些信息添加到concurrentHashmap中。从多个线程调用 processPresenceAvailableAgent 函数。我在这里打电话给获取,包含密钥(), putifabsent ()函数。到目前为止,我知道concurrenthashmap的这些函数集是线程安全的,但我调用多个函数,所以这些复合代码块也是线程安全的吗?请解释我
private ConcurrentHashMap> agentInfoMapByOpCode;
public void processPresenceAvailableAgent(Packet packet)
{
if(debug)logger.debug("start-----------processPresenceAvailableAgent()");
String opcode= packet.getAttribute("opcode");
String fromJID= packet.getStanzaFrom()!=null?packet.getStanzaFrom().toString():null;
ConcurrentHashMap agentInfoMap=agentInfoMapByOpCode.get(opcode);
if(agentInfoMap==null)
{
agentInfoMap=new ConcurrentHashMap();
agentInfoMapByOpCode.putIfAbsent(opcode,agentInfoMap);
}
if(!agentInfoMap.containsKey(fromJID))
{
AgentInfo ainfo=new AgentInfo();
ainfo.setUserJID(fromJID);
ainfo.setOnlineStatus("available");
ainfo.setOperatorCode(opcode);
agentInfoMap.putIfAbsent(fromJID,ainfo);
addNewAgentToAgentQueue(opcode,fromJID);
if(debug)
{
logger.debug("agent " + fromJID+ " has been added");
logger.debug("agentinfo map size()=" + agentInfoMap.size()+" for operator code "+opcode);
}
}
assignAgentToNewVisitor(opcode); //check visitor waiting queue and send visitor available chat request message to agent
if(debug)logger.debug("end-----------processPresenceAvailableAgent()");
}