Interrupt on Java thread..  
Author Message
Ed Thompson





PostPosted: 2004-7-9 22:49:00 Top

java-programmer, Interrupt on Java thread.. I have two threads, one reading from stdin and writing to a socket
(requestThread),
one reading from a socket and writing to stdout (responseThread).

When the response thread gets a msg from server that an error occurs, it
closes the socket and calls interrupt() for it's thread group before
exiting.

But requestThread never seems to get the interrupt.
It is blocked(?) on a readLine() from the BufferedReader omn stdin.


What am I doing wrong?
 
Michael Borgwardt





PostPosted: 2004-7-9 22:57:00 Top

java-programmer >> Interrupt on Java thread.. Ed Thompson wrote:
> When the response thread gets a msg from server that an error occurs, it
> closes the socket and calls interrupt() for it's thread group before
> exiting.
>
> But requestThread never seems to get the interrupt.
> It is blocked(?) on a readLine() from the BufferedReader omn stdin.
>
>
> What am I doing wrong?

Thread.interrupt() does not work for normal blocking IO, only for
implementors of java.nio.channels.InterruptibleChannel.

Instead, calling close() on the Reader works on most VMs (throws an
IOException in the blocked thread), but it's not specified behaviour.

 
Ed Thompson





PostPosted: 2004-7-10 1:19:00 Top

java-programmer >> Interrupt on Java thread.. Michael Borgwardt wrote:
> Instead, calling close() on the Reader works on most VMs (throws an
> IOException in the blocked thread), but it's not specified behaviour.
>

Tried that, but I suspect no IOException is being thrown since the
reader is built on stdin.