Interrupting TCP Socket
In my application I build up TCP connections with the clients. We are in the developing phase so I need to reload the server frequently. The Server runs under tomcat, and when I try to stop the server, the Socket connection managing threads freeze and I have to kill whole tomcat to stop them. When the thread get an interruptedException it don't even notice it...
Until now I used socketTimeOut for my applications and a sleep at the end of the listening cycle as a breakpoint, but in this application I need to interrupt the already built sockets and the BufferedInputStream over it.
How can I solve this problem?
Thanks:
Bence
[661 byte] By [
bencea] at [2007-11-26 12:36:14]

# 1
Hi,Do you have access to the stream? The thread will probably not get interrupted exception, but one way is to close the streams instead. The thread will in that case return from the blocking call.Kaj
# 2
Yeah, I have, but will it throw some kind of exception itself when it get an InterruptedException(i haven't recognized something like this), or do I have to put a sleep(1) into the end of the listening cycle, and catch the InterruptedException myself?Thanks:Bence
# 3
Create SocketChannels and ServerSocketChannels, and get the sockets from them. Stay in blocking mode and proceed as before once you have these sockets. You can interrupt blocking operations (accept(), read(), write() on this kind of socket with Thread.interrupt(). This will close the socket and throw java.nio.channels.ClosedByInterruptException.
ejpa at 2007-7-7 16:02:02 >
