请确认此 XMPP 代码不是线程安全的

发布于 2024-07-17 05:38:55 字数 723 浏览 2 评论 0原文

我正在阅读 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心如荒岛 2024-07-24 05:38:55

看起来这是一个已知错误

Looks like it's a known bug.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文