Re: Mutable Objects and Thread Boundaries
On 7/21/2010 3:15 PM, Lew wrote:
Alan Gutierrez wrote:
With a terminal value to shutdown the queue, and with the thread
unexposed to the client, there seems to be no way to send an interrupt
to the thread, so it becomes the classic unreachable checked exception
block.
'InterruptedException' is not about SIGINT or other OS signals, but
about the Java method 'Thread#interrupt()'.
<http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/
lang/Thread.html#interrupt()>
<http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/java/
lang/InterruptedException.html>
There is excellent advice in /Java Concurrency in Practice/ (JCIP.
Part of the reason to catch it is that the JVM apparently can throw
spurious 'InterruptedException's.
Read JCIP (by Brian Goetz et al.).
I think you've misinterpreted something. There are possible spurious
wake-ups, but there are *not* spurious interrupts. Object.wait(...) may
*return* before the conditions are met, but will not through
InterruptedException unless there is a true interrupt.
BTW, there *is* an evil way to kill other threads, whether they handle
interrupted or not. Thread.stop(throwable);
<http://download.oracle.com/docs/cd/E17476_01/javase/1.5.0/docs/api/java/lang/Thread.html#stop%28java.lang.Throwable%29>
--
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>