Is there a way for a thread to tell which thread has interrupted it?
Eg.:
...
if (isInterrupted()) {
// look-up the thread that interrupted this
// act accordingly
}
Thread isn't showing anything.
//========================
EDIT:
It isn't a message or event mechanism i'm looking for.
but, this as is seems very raw. a way to get the class type, thread group or maybe just the priority of the interrupting thread would carry some info to work on.
typical use is system shut-down-- interrupting them all to get them out of their blocking methods, and there isn't another i can think of now.
Is there a way for a thread to tell which thread has interrupted it?
In a word: No.
There is no functionality in that standard Java SE class libraries that support this.
Indeed, even the problem is not well defined:
What happens if a thread is interrupted multiple times by different threads? Which one should be reported?
What about race conditions between a thread detecting that it has been interrupted (e.g. via a isInterrupted
call) and finding out what thread did it?
As Sotirios commented: if the signalled thread needs to find out which thread signalled it, then interrupt
is probably the wrong mechanism. You probably to build your own event mechanism in which the events carry the information you need with them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With