Java WebSockets: The remote endpoint was in state [TEXT_FULL_WRITING]

本文探讨了在Java WebSocket中使用Tomcat容器时遇到的一个bug:多线程尝试同时向同一个WebSocket session写数据时引发的错误。文章提供了一个解决方案,即通过使用synchronized关键字同步代码块,并采用getBasicRemote()方法发送消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

java Websocket 多线程向同一个session写数据,容器为tomcat

目前发现的问题是tomcat的一个bug,解决方案是:

public void sendMessage(String message) throws IOException {
        synchronized(this.session) {

            this.session.getBasicRemote().sendText(message);
        }
        //this.session.getAsyncRemote().sendText(message);
    }

 

使用synchronized和getBasicRemote,使用getAsyncRemote的话也会报错

 

https://stackoverflow.com/questions/22257079/java-websockets-the-remote-endpoint-was-in-state-text-full-writing

https://bz.apache.org/bugzilla/show_bug.cgi?id=56026

https://www.cnblogs.com/interdrp/p/4866129.html

http://blog.youkuaiyun.com/luoruixiaohai/article/details/50960319

https://stackoverflow.com/questions/33381420/tomcat-throws-the-remote-endpoint-was-in-state-binary-full-writing-when

转载于:https://my.oschina.net/ryanzl/blog/1622135

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值