一个奇怪的问题寻求高高手
一个简单的websocket的通信servlet
ChatAnnotation 是websocket实现类
首先用private static final的哈希表对所有ChatAnnotation 实例进行组织
private static final Hashtable<String, ChatAnnotation> connectionscom=new Hashtable<String, ChatAnnotation>();
当一个通道发送自己的标识字符串时,把该通道实例放到hashtable中,并以标识comid做索引即
connectionscom.put(this.comid,this);
当需要和指定通道发消息时,用ChatAnnotation client=connectionscom.get(curcallcomid);检索出通道实例来,然后往指定通道
发消息
client.session.getBasicRemote().sendText("comming"+":"+callid);
现在的问题是:
开始一切正常,但发现过了大概2小时后,ChatAnnotation client=connectionscom.get(curcallcomid);取出的是NUll
而实际上该通道的心跳都正常,也就是客户端和服务器servlet仍然保持通信,但private static final的哈希表感觉丢失掉了,这是怎么回事
,请高高手指点一下,这个问题有点令人困惑啊