Red5:是否可以将 IConnection 实例存储在 HashMap 中以便稍后检索
我在应用程序 connect
中定义了一个像这样的 HashMap
HashMap<String, IConnection> connections = new HashMap<String, IConnection>();
,我像这样向其中添加值:
conn.setAttribute(“username”, username);
connections.put(username, conn); // username and conn are parameters passed to
// connect method
在应用程序 disconnect
方法中,我从中删除值 这似乎
connections.remove((String)conn.getAttribute(“username”));
可行,但它正确/安全吗?还是我做错了?
I have a HashMap
defined like this
HashMap<String, IConnection> connections = new HashMap<String, IConnection>();
inside application connect
, I add values into it like this:
conn.setAttribute(“username”, username);
connections.put(username, conn); // username and conn are parameters passed to
// connect method
inside application disconnect
method, I remove values from it like this
connections.remove((String)conn.getAttribute(“username”));
This seems to work, however is it correct/safe? Or am I doing it wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,没关系,但我建议您在尝试访问或写入之前确保连接仍然处于连接状态。
Yes, it is alright but I suggest that you make sure the connection is still connected before you try to access or write to it.