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!

Socket getting closed when closing Stream

843790Jul 26 2010 — edited Jul 26 2010
Hi,

I am creating a pool of sockets (using apache commons pool) but I am not able to release the socket to the pool since the socket is getting closed when I am closing the inputstream. Since my socket is getting closed each time a request is being processed, each time a new socket object has to be created and I am not able to use my pool. In the below piece of code the looger returns false before closing the inputstream and true after closing the input stream.
		} finally {

			try {
				logger.error("before Closing streams=" + socket.isClosed());
				if (in != null) {
					in.close();
				}
				logger.error("after Closing input streams="  + socket.isClosed());
				if (out != null) {
					out.close();
				}
			} catch (Exception e) {
				logger.fatal("Exception occured while closing the connection",e);
			}

		}
If I donot close the input/output streams and I try to use the socket again, I get an exception that says -
java.net.SocketException: Software caused connection abort: socket write error
	at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:103)
	at java.net.SocketOutputStream.write(SocketOutputStream.java:147)
	at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1849)
	at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1758)
	at java.io.ObjectOutputStream.<init>(ObjectOutputStream.java:237)
	at com.ibm.dth.adaptor.socket.server.NDSSocket.processRequest(NDSSocket.java:57)
	at com.ibm.dth.adaptor.socket.service.impl.NDSAdaptorServiceImpl.invokeCommand(NDSAdaptorServiceImpl.java:56)
	at com.ibm.dth.adaptor.test.nds.TestNDS.testService(TestNDS.java:28)
	at com.ibm.dth.adaptor.test.nds.TestNDS.run(TestNDS.java:70)
	at java.lang.Thread.run(Thread.java:735)
Pls guide how can I stop the socket from getting closed so that I can release the socket to the pool and re-use it.

Regards,
Ashish
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 23 2010
Added on Jul 26 2010
6 comments
718 views