This is the mail archive of the
java-discuss@sourceware.cygnus.com
mailing list for the Java project.
Re: Thread.interrupt()
- To: java-discuss at sourceware dot cygnus dot com
- Subject: Re: Thread.interrupt()
- From: Bryce McKinlay <bryce at albatross dot co dot nz>
- Date: Tue, 14 Mar 2000 10:33:43 +1300
- References: <38CCAD8B.5F7B8259@albatross.co.nz>
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