I've java process which reads data from a socket. Below is the code for reading the data from the socket. The program creates a ServerSocketChannel
and binds it to a socket and accepts the connection from the socket.
Then it creates a bytebuffer with a specified capacity and reads data from the SocketChannel by filling this buffer. This particular logic runs in an
infinite loop, as there is continuous flow of data.
I'm pasting the code below:
The process runs for sometime, reads the data and hangs after sometime at the SocketChannel read() method. I took the thread dump of the process which is below:
at sun.nio.ch.FileDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:38)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:258)
at sun.nio.ch.IOUtil.read(IOUtil.java:225)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:223)
If i restart the process, it starts processing the data again and after sometime goes in to a hung state.
One more thing I noticed is that there are lot of CLOSE_WAIT connections on the socket in which the process is reading data.
Can any one help in identifying what is going wrong here?
[ October 03, 2008: Message edited by: Ganesh Dhakshinamurthy ]
Please
use code tags [ October 03, 2008: Message edited by: Joe Ess ]