• Post Reply Bookmark Topic Watch Topic
  • New Topic

Interrupt a thread blocking on IO  RSS feed

 
Brian Podolny
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
try that...

[This message has been edited by Pierre-Fran�ois Lemosquet (edited August 28, 2001).]
 
Brian Podolny
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!