Mutable Objects and Thread Boundaries

L

Lew

Daniel said:
Actually, thats on page 93.

That's funny, actually I quoted it from the passage in the book that actually
I had open to p. 142 as I actually typed. Actually.
 
C

ClassCastException

Actually, thats on page 93.

Page 143 does state:
"Only code that implements a thread's interruption policy may swallow an
interruption request."

So there are three possible responses:
1. Propagate the exception
2. Restore the interruption status.
3. Swallow the interrupt, but *only* if your code is part of the
thread lifecycle management.

So, the original advice of either propagate the exception or restore the
interruption status was aimed at library authors writing methods that
might have to handle InterruptedException but that aren't supposed to
know about (or care about, or interfere with) the caller's management of
threads.
 
C

ClassCastException

That's funny, actually I quoted it from the passage in the book that
actually I had open to p. 142 as I actually typed. Actually.

Probably there's more than one version of it out there, and the page
numbers aren't the same from one to the next. That frequently happens
with the paperback vs. the hardback version of a book, and also happens
when technical-topic books are republished with updates or addenda every
few years. Besides the updates moving everything that comes after them,
they may retypeset everything and change the style and the like, which
will move things around.

That said, a shift from page 93 to page 142 is large, nearly 50 pages.
Either the 142 is from a paperback with 2/3 as much on each page as the
hardback, or they significantly added material or rearranged sections in
a revision at some point.
 
M

markspace

ClassCastException said:
So, the original advice of either propagate the exception or restore the
interruption status was aimed at library authors writing methods that
might have to handle InterruptedException but that aren't supposed to
know about (or care about, or interfere with) the caller's management of
threads.


This is exactly correct. He says, "For library code, there are
basically two choices[:] propagate the exception [or] ...restore the
interrupt"

He does go on to say even there (p. 93) that it is ok to catch and
ignore the exception if you are implementing code that is highest up the
call stack in a Thread.

BTW, the difference in page numbers is because Goetz talks about
interrupts in (at least) two places. Once in chapter 5, where he
discusses various synchronizers like deques and blocking queues (some of
which throw InterruptedException). And then again in chapter 7,
including p. 143, where he explicitly talks about cancellation of a task.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top