请确认此 XMPP 代码不是线程安全的
我正在阅读 Smack api 的源代码,方法 XMPPConnection#disconnect 如下所示:
public void disconnect(Presence unavailablePresence) {
// If not connected, ignore this request.
if (packetReader == null || packetWriter == null) {
return;
}
shutdown(unavailablePresence);
if (roster != null) {
roster.cleanup();
roster = null;
}
wasAuthenticated = false;
packetWriter.cleanup();
packetWriter = null;
packetReader.cleanup();
packetReader = null;
}
在我的场景中,我将实时 XMPPConnection 存储在名为 Session 的类中。 一个单独的执行线程将尝试通过调用 Session#shutdown() 来关闭我的 XMPPConnection 实例。 在我看来,我必须通过获取互斥体或其他东西来配合告诉 Session 关闭 XMPPConnection。 正确的?
I'm reading the source code to the Smack api and the the method XMPPConnection#disconnect looks like this:
public void disconnect(Presence unavailablePresence) {
// If not connected, ignore this request.
if (packetReader == null || packetWriter == null) {
return;
}
shutdown(unavailablePresence);
if (roster != null) {
roster.cleanup();
roster = null;
}
wasAuthenticated = false;
packetWriter.cleanup();
packetWriter = null;
packetReader.cleanup();
packetReader = null;
}
In my scenario, I am storing a live XMPPConnection inside a class called Session.
A separate thread of execution will attempt to close my instance of XMPPConnection by calling Session#shutdown(). As I see it, I will have to cooperatively tell Session to close the XMPPConnection by acquiring a mutex or something. Correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来这是一个已知错误。
Looks like it's a known bug.