> methods of Selector. Assuming that select() does, in fact, block even
> if the current thread's interrupt status is set, is there any
> alternative to simply checking Thread.interrupted() prior to calling
> select() and taking appropriate action (i.e., throwing an
> InterruptedException manually)?

Signature
Knute Johnson
email s/nospam/knute/
> "If this thread is blocked in a Selector then the thread's interrupt
> status will be set and it will return immediately from the selection
> operation, possibly with a non-zero value, just as if the selector's
> wakeup method were invoked."
Yes, I've read that, but it only incompletely answers my question.
> Thread.sleep(), Thread.join() and Object.wait() will all throw
> InterruptedExceptions if their threads are interrupted.
I know about Object.wait(), because the docs say so. Can you point me
to a a reference (possibly in the documentation) that says the same
thing about Thread.sleep()? Also of immediate interest to me is how
blocking operations on Channels respond when the current thread has
already been interrrupted; sadly, again I have no evidence from the
documentation that they handle the situation intelligently.
> In all other cases the interrupt status of the thread is set so that you
> can detect it with Thread.isInterrupted() or Thread.interrupted(). Note
> the difference between the two, interrupted() clears the interrupt
> status while isInterrupted() doesn't.
Yes, that's what I'm doing, but it seems silly to have to do so in
light of the fact that Object.wait() is smart enough to handle the
situation.

Signature
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Knute Johnson - 15 Jun 2006 23:41 GMT
>> "If this thread is blocked in a Selector then the thread's interrupt
>> status will be set and it will return immediately from the selection
>> operation, possibly with a non-zero value, just as if the selector's
>> wakeup method were invoked."
>
> Yes, I've read that, but it only incompletely answers my question.
I've really not played with Selectors so I can't help you with those.
>> Thread.sleep(), Thread.join() and Object.wait() will all throw
>> InterruptedExceptions if their threads are interrupted.
[quoted text clipped - 5 lines]
> already been interrrupted; sadly, again I have no evidence from the
> documentation that they handle the situation intelligently.
Look at Thread.interrupt(). The last line is really the most important
one "If none of the previous conditions hold then this thread's
interrupt status will be set." If it is not blocked on sleep(), wait()
or join() it will set the interrupt status. When it encounters a
sleep(), wait() or join() it will then throw an InterruptedException.
>> In all other cases the interrupt status of the thread is set so that you
>> can detect it with Thread.isInterrupted() or Thread.interrupted(). Note
[quoted text clipped - 4 lines]
> light of the fact that Object.wait() is smart enough to handle the
> situation.
If you need to detect it before it reaches one of the interruptible
methods you will have to test for it. I don't see where this is silly.
You call interrupt, it sets a flag, you test for it, I don't know how
else you would do it.

Signature
Knute Johnson
email s/nospam/knute/