Clientabortexception: java.net. socketexception: Connection reset by peer: Socket write error
I. exception description:
When you use jfreechart to output chart images to a browser, if the refresh is too fast, the following exception occurs:
Clientabortexception: java.net. socketexception: Connection reset by peer: Socket write error
The Code is as follows:
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. flus+fore (filecacheimageoutputstream. Java: 230)
At javax. ImageIO. Stream. imageinputstreamimpl. Flush (imageinputstreamimpl. Java: 811)
At com.sun.imageio.plugins.jpeg. Adjust imagewriter. Write (using imagewriter. Java: 1027)
At org. jfree. Chart. encoders. sunbench encoderadapter. encode (sunbench encoderadapter. 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
Ii. Cause Analysis
I found the following reason in Baidu:
Clientabortexception:Java.net. socketexception: Connection reset by peer: Socket write error is caused by a "clientabortexception ", it is an exception in I/O processing and should be captured by the application server.
Connection reset by peerCause:
Frequent Connection reset by peer: there may be many reasons, but the more common reasons are:
①: When the number of concurrent connections on the server exceeds its capacity, the server will shut down some of the connections;
②: The client closes the browser, and the server is still sending data to the client;
③: The browser presses stop.
Many people say that it is caused by the client and there is no way to control it. This is a depressing problem.
However, a buddy said well, ifClientabortexception:Yes. Do not output these exceptions.
Specific methods
Code:
- Try {
- // Put the processing code in try ...... In the Catch Block, use the judgment function in the catch part to prevent the system from throwing clientabortexception,
- Chartutilities. writechartasjpeg (response. getoutputstream (), chart, 600,400 );
- } Catch (exception e ){
- String simplename = E. getclass (). getsimplename ();
- If ("clientabortexception". Equals (simplename )){
- System. Out. println ("refreshing the client too fast ");
- } Else
- E. printstacktrace ();
- }
- Return Mapping. findforward ("succ ");
- }
Iii. Conclusion
This is acceptable.