【ClientAbortException】ClientAbortException: java.net.SocketException 冷不防 2023-01-15 04:54 75阅读 0赞 ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error 一.异常说明: 用JFreeChart 往浏览器输出图表图片时,如果刷新太快,就有如下异常 ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error 代码如下: ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434) at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349) at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381) at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370) at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89) at javax.imageio.stream.FileCacheImageOutputStream.flushBefore(FileCacheImageOutputStream.java:230) at javax.imageio.stream.ImageInputStreamImpl.flush(ImageInputStreamImpl.java:811) at com.sun.imageio.plugins.jpeg.JPEGImageWriter.write(JPEGImageWriter.java:1027) at org.jfree.chart.encoders.SunJPEGEncoderAdapter.encode(SunJPEGEncoderAdapter.java:173) at org.jfree.chart.encoders.EncoderUtil.writeBufferedImage(EncoderUtil.java:137) at org.jfree.chart.ChartUtilities.writeChartAsJPEG(ChartUtilities.java:443) at org.jfree.chart.ChartUtilities.writeChartAsJPEG(ChartUtilities.java:389) Caused by: java.net.SocketException: Connection reset by peer: socket write error at java.net.SocketOutputStream.socketWrite0(Native Method) at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) at java.net.SocketOutputStream.write(SocketOutputStream.java:136) at org.apache.coyote.http11.InternalOutputBuffer.realWriteBytes(InternalOutputBuffer.java:741) at org.apache.tomcat.util.buf.ByteChunk.flushBuffer(ByteChunk.java:434) at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:349) at org.apache.coyote.http11.InternalOutputBuffer$OutputStreamOutputBuffer.doWrite(InternalOutputBuffer.java:765) at org.apache.coyote.http11.filters.ChunkedOutputFilter.doWrite(ChunkedOutputFilter.java:126) at org.apache.coyote.http11.InternalOutputBuffer.doWrite(InternalOutputBuffer.java:574) at org.apache.coyote.Response.doWrite(Response.java:560) at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:353) ... 47 more 二.原因分析 在BAIDU找了下原因,大概归结为: ClientAbortException: java.net.SocketException: Connection reset by peer: socket write error的原因是由于处理http连接时,正在输出内容时,用户关闭了IE,会出现一个"ClientAbortException",属于I/O处理中出现的一个异常,应用服务器应该会捕捉。 Connection reset by peer的原因: 经常出现的Connection reset by peer: 原因可能是多方面的,不过更常见的原因是: ①:服务器的并发连接数超过了其承载量,服务器会将其中一些连接Down掉; ②:客户关掉了浏览器,而服务器还在给客户端发送数据; ③:浏览器端按了Stop 很多人都说是客户端造成的,没有办法控制,是个比较郁闷的问题。 但是有个哥们说的很好,如果ClientAbortException:是可以不输出这些异常 具体办法 Code: try \{ //处理代码放在try……catch块中,在catch部分使用判断避免让系统抛出ClientAbortException, ChartUtilities.writeChartAsJPEG(response.getOutputStream(), chart, 600, 400); \} catch (Exception e) \{ String simplename = e.getClass().getSimpleName(); if("ClientAbortException".equals(simplename))\{ System.out.println("客户端刷新太快了"); \}else e.printStackTrace(); \} return mapping.findForward("succ"); \} 三.结论 这样做是可以的。 ———————————————— 版权声明:本文为CSDN博主「和平强大平和」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/welcomeni/article/details/6505668
还没有评论,来说两句吧...