笔者使用websocket进行通信,服务器异步返回。websocket服务器又异步调用其他websocket,也是异步访问。
由于无法预测服务器调用第三方websocket什么时候调用结束,使用了CountDownLatch。
每次报错都如下:
java.lang.reflect.InvocationTargetException: null at sun.reflect.GeneratedMethodAccessor419.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:45005) at java.lang.reflect.Method.invoke(Method.java:498) at org.yeauty.pojo.PojoEndpointServer.doOnMessage(PojoEndpointServer.java:180) at org.yeauty.standard.WebSocketServerHandler.handleWebSocketFrame(WebSocketServerHandler.java:39) at org.yeauty.standard.WebSocketServerHandler.channelRead0(WebSocketServerHandler.java:19) at org.yeauty.standard.WebSocketServerHandler.channelRead0(WebSocketServerHandler.java:9) at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:105) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:310) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:284) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1434) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:965) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:163) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) Caused by: java.lang.IllegalMonitorStateException: null at java.lang.Object.wait(Native Method) at java.lang.Object.wait(Object.java:502) at com.xxx.web.open.ws.RealTimeTTSEndpoint.onSendEOS(RealTimeTTSEndpoint.java:142) at com.xxx.web.open.ws.RealTimeTTSEndpoint.onMessage(RealTimeTTSEndpoint.java:103) ... 28 common frames omitted
后来查代码看看,是
CountDownLatch.await()方法手误写成CountDownLatch.wait()
注意await与wait一字之差。
错误:
connectClose.wait();
正确:
connectClose.await();
本博客文章绝大多数为原创,少量为转载,代码经过测试验证,如果有疑问直接留言或者私信我。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。
创作文章不容易,转载文章必须注明文章出处;如果这篇文章对您有帮助,点击右侧打赏,支持一下吧。