For me, a thread that waits on a blocking IO can not be interrupted
because a thread can only be interrupted if it's in wait or sleep state.
That's why nio has been added to the JDK.
There's the InterruptibleChannel class which SocketChannel implements:
"A channel that implements this interface is also interruptible: If a
thread is blocked in an I/O operation on an interruptible channel then
another thread may invoke the blocked thread's interrupt method. This
will cause the channel to be closed, the blocked thread to receive a
ClosedByInterruptException, and the blocked thread's interrupt status to
be set."
But this doesn't solve my problem...
Luc
>> Hi,
>>
[quoted text clipped - 11 lines]
>
> robert
Karl Uppiano - 23 Oct 2006 00:25 GMT
> For me, a thread that waits on a blocking IO can not be interrupted
> because a thread can only be interrupted if it's in wait or sleep state.
[quoted text clipped - 11 lines]
>
> Luc
In my experience, a thread blocking in a classic Java socket will not
interrupt. Calling wakeup on a waiting NIO socket will bring a waiting
thread back to you.
> Are you sure you actually need nio? AFAIK classes in java.io honor
> Thread.interrupt() and you get an InterruptedIOException which is a
> subclass of IOException.
I don't believe that's correct. java.io classes do not reliably honor
Thread.interrupt(), although the situation can be worked around by
closing the associated stream, causing an exception to be thrown. If
nio isn't an option for OP, that might be the poor man's workaround.

Signature
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Thomas Hawtin - 23 Oct 2006 16:35 GMT
>> Are you sure you actually need nio? AFAIK classes in java.io honor
>> Thread.interrupt() and you get an InterruptedIOException which is a
[quoted text clipped - 4 lines]
> closing the associated stream, causing an exception to be thrown. If
> nio isn't an option for OP, that might be the poor man's workaround.
I thought interruptible I/O had been fixed for some time. So I checked
the bug database:
"As of today, the interruptable io has officially deprecated. We are not
going to fix this bug. However, we leave the current implementation as
it is for backward compatibility.
" xxxxx@xxxxx 1999-09-12"
-- http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4103109
I haven't seen that anywhere else.
Tom Hawtin
Chris Uppal - 23 Oct 2006 18:56 GMT
> I thought interruptible I/O had been fixed for some time. So I checked
> the bug database:
[quoted text clipped - 8 lines]
>
> I haven't seen that anywhere else.
The writeup of 4154947 (referenced from that bug) at:
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4154947
also makes interesting (if sad, and salutary) reading.
-- chris
Mark Thornton - 23 Oct 2006 17:46 GMT
>>Are you sure you actually need nio? AFAIK classes in java.io honor
>>Thread.interrupt() and you get an InterruptedIOException which is a
[quoted text clipped - 4 lines]
> closing the associated stream, causing an exception to be thrown. If
> nio isn't an option for OP, that might be the poor man's workaround.
I think closing the associated stream only works on some operating systems.