Thread.interrupt()

Bryce McKinlay bryce@albatross.co.nz
Mon Mar 13 13:33:00 GMT 2000


Bryce McKinlay wrote:

> Is there any online documentation where the semantics of
> thread.interrupt() are fairly precisely specified? It isn't mentioned in
> either the JLS or JVM spec, and the API documentation is a little bit...
> vague.

Specifically, I was under the impression that Thread.interrupt() should
interrupt a thread that is blocking on an I/O operation (Socket.read() etc)
- otherwise what is InterruptedIOException for? However, from reading posts
to Sun's java discussion forums [*], it appears that this is not the case,
at least for recent JDKs. Is it worth trying to implement this?

Also, regarding interaction between interrupt() and wait(): suppose we have
4 threads. Two of these (1&2) are blocked on wait() for the monitor "a".
Simultaniously, thread 3 calls a.notify() and thread 4 calls
thread1.interrupt(). My guess is that the correct behaviour is for EITHER
thread 1 to wake up normally, but also have its interrupt status flag set,
or for thread 2 to wake up normally and thread 1 to wake up with an
InterruptedException. Is this correct?

regards

  [ bryce ]

[*]:
http://forum2.java.sun.com/forum?14@@.787b6e5f
http://forum2.java.sun.com/forum?14@@.ee778af




More information about the Java mailing list