Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Intermittent "socket closed" exception

2699920Jun 24 2014 — edited Jul 24 2014

We have a servlet application running under jboss 7.1.1/java 1.7 that sends http requests to another server. Everything works fine for most of the time, but occasionally (from one to a couple of times a day) we get a “Socket closed” exception.  I’ve been trying to find out what might be causing this but so far I’ve been unsuccessful. By the way, this has been happening while the application was running under older versions of Jboss/Java so the version might not be that relevant.

Here’s an excerpt from the method where this happens:

. . . . .

try

{

HttpURLConnection conn = (HttpURLConnection) urlEndpoint.openConnection();

   conn.setRequestMethod("POST");

   conn.setDoInput(true);

   conn.setDoOutput(true);

   conn.setRequestProperty("Content-Type", "text/xml; charset=UTF-8");

   conn.setRequestProperty("charset", "UTF-8");

   DataOutputStream out = new DataOutputStream(conn.getOutputStream());

   out.write(env.getBytes("UTF-8"));

   out.flush();

   out.close();

   InputStream iss = null;

   conn.connect();

try

{

iss = conn.getInputStream(); // this is where the exception is cought

. . . . . .

And here’s what the exception looks like:

. . . . . .

  1. java.net.SocketException: socket closed

                at java.net.SocketInputStream.socketRead0(Native Method)

                at java.net.SocketInputStream.read(SocketInputStream.java:150)

                at java.net.SocketInputStream.read(SocketInputStream.java:121)

                at java.io.BufferedInputStream.fill(BufferedInputStream.java:235)

                at java.io.BufferedInputStream.read1(BufferedInputStream.java:275)

                at java.io.BufferedInputStream.read(BufferedInputStream.java:334)

                at sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:633)

                at sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:579)

                at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1322)               

. . . . . .

In my investigation I  came across some posts that were mentioning the sockets pool the http connection is keeping, but I’m not sure whether and how this can help me solve the problem I have.

I’ve now exhausted all the ideas I had and I would be grateful for any help.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 21 2014
Added on Jun 24 2014
3 comments
5,814 views