Ron writes:
> I've got a problem when using the Thread.interrupt() method.  It doesn't
> seem to be working.
> [...]
> However if I call a interrupt on Thread2
> then it returns a socket error, so it is affecting Thread2 in some way.
> 
> I guess interrupt just sets a flag, so how come it is not getting picked
> up in Thread1...

For some reason, Thread.interrupt() does *only one* of the following:

  - throw an Exception (InterruptedException, or one of the many
    I/O-related exceptions that can be caused by an interrupt), or

  - set the interrupted() flag.

To me, that behavior is very unexpected, and I'm not sure why it is
the way it is.  To get around it, I write

     catch (InterruptedException e) {
           Thread.currentThread().interrupt();
           // whatever other processing you might want to do
     }

for almost every InterruptedException.  It's trickier for the other
interruption-related exceptions, but you can usually find a way to do
what you want.

Best,
daniel dulitz

Valley Technologies, Inc.               Peak Performance Real-Time DSP
State College, PA


----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]

Reply via email to