Hi Jim,
How and where you place the catch block (if you use one) will determine whether the method keeps executing or not, and what exactly it does when interrupted.
As the InterruptedException is a checked one, you have no real choice catching it
somewhere or not.
I can't even tell what the question was at that point.
My position (and I couldn't get it validated in that long thread) is that interrupt() just sends a signal to the running thread that it should interrupt itself. That "signal" is a simple boolean flag. When the target thread is running, it can check that flag. The problem comes with a target thread being in a wait state : how could it check its interrupted flag as, by definition, it's doing nothing ? The solution is given by the InterruptedException which is thrown to a thread which is interrupted while in a wait stait.
The whole discussion (within another main subject) turned around InterruptedException and the way the coder should handle it. Most of people in this discussion suggested to throw some RuntimeException, arguing that such an interruption should never happen. My position was quite different in the context of a general-purpose class (a MultiReadSingleWriteSynchronizer class) from where I couldn't make any assumption on the context in which my class would be used. So I chose to call Thread.currentThread().interrupt() from the catch block, to offer my class what I called "Thread interruption transparency". As the InterruptedException has as side effect to swallow the interrupted flag (as interrupted() does BTW), calling interrupt() from the catch block is the only way I found out to let my MultiReadSingleWriteSynchronizer class usable by a class which would count on isInterrupted().
Now as nobody agreed with my position there (despite my numerous efforts
), I thought that Marlene could help me in convincing myself that what I wrote there makes some sense.
Now I think that such an issue is more a language question than a development one, in such a way that this forum (
SCJP) may be more appropriate than the SCJD one for this sort of theoritical stuff.
Anyway I guess that, as usual, Marlene will give us some useful opinion of her !
Thank you in advance !
Best,
Phil.
[ December 15, 2003: Message edited by: Philippe Maquet ]