public class SipResponseCollection {
private final static Logger LOGGER=Logger.getLogger(SipResponseCollection.class);
private volatile Map<String, List<SipResponse>> map = new HashMap<String, List<SipResponse>>();
public SipResponseCollection() {
}
public boolean contain(String callId, int statusCode) {
List<SipResponse> list = map.get(callId); //pop null exception in linux amd64 machine but right for windows machine. callId is not null.
if(list==null)
return false;
for (SipResponse sipResponse : list) {
if (sipResponse.getStatusCode() == statusCode)
return true;
}
return false;
}
}
在 new SipResponseCollection() 之后,如果 volatile 映射可以为空?我在不同的机器上运行,一台机器提示空异常。但删除关键字后: volatile ,一切正常。为什么?
ps:没有任何公共方法可以将地图设置为空。