HttpURLConnection connection reset error handling

I have server client java application running on version SE6. Messaging between server and client is via http protocol. Generally this application was running well but lately I start to see some "connection reset" errors on client side logs. I thought it can be because of keep alive and disabled it but error still there. Here is the client side error log.

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:208)
    at java.net.SocketInputStream.read(SocketInputStream.java:134)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:247)
    at java.io.BufferedInputStream.read1(BufferedInputStream.java:287)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:346)
    at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:717)
    at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:663)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1336)
    at cb.smg.general.utility.ESIHttpCaller.executePost(ESIHttpCaller.java:43)

I know a problem on the server side, if worker thread pool is full socket is closed without and appropriate http code on the server side and client we get java.net.SocketException: Unexpected end of file from server. Bu that should be very rare. My first question can this error(connection reset) be because of some changes outside of application (for instance OS fix.) And secondly what is the best way to handle this exception, currently I just call the below method in finally block.

HttpURLConnection.disconnect()

if worker thread pool is full socket is closed without and appropriate http code on the server side and client we get java.net.SocketException: Unexpected end of file from server.

Or 'connection reset'. It depends on whether you are reading or writing at that moment.

My first question can this error(connection reset) be because of some changes outside of application (for instance OS fix.)

No.

And secondly what is the best way to handle this exception, currently I just call the below method in finally block.

Good idea.

链接地址: http://www.djcxy.com/p/56572.html

上一篇: 哪个Java套接字抛出Connection重置IOException?

下一篇: HttpURLConnection连接重置错误处理