How can you interrupt a thread that is blocking on IO. I have a thread which is in an infinite loop, which keeps calling ServerSocket.accept(); Interrupting this thread does nothing until it receives a client connection because it is blocked on the accept() method. Any suggestions? Thanks, Brian Podolny
Anonymous
Ranch Hand
Joined: Nov 22, 2008
Posts: 18944
posted
0
Hi! try that...
[This message has been edited by Pierre-Fran�ois Lemosquet (edited August 28, 2001).]
Brian Podolny
Ranch Hand
Joined: Aug 29, 2000
Posts: 32
posted
0
Thanks for the reply but I don't think that solves the problem. The thread is still blocked on the accept(). The stop() method is the right way to shut down but it will not be invoked. Maybe I'm missing something...
Xavier Casals
Greenhorn
Joined: Aug 16, 2001
Posts: 4
posted
0
Have you tried to use 'setSoTimeout'? It interrupts accept() when timeout expires. Then you can decide if you want to finish or not. Is like an active wait ... but I don't know if there is a better solution. I have never programmed with sockets in Java, but I think it can work ...
Brian Podolny
Ranch Hand
Joined: Aug 29, 2000
Posts: 32
posted
0
That's a good solution Xavier. Thanks. I'm not crazy about the active wait, so I 'll keep thinking on it but if I can't come up with anything than your solution is my way to go.