[concurrency-interest] Advice on tracking down the caller of Thread.interrupt()?

Bryan Thompson bryan at systap.com
Wed Mar 21 15:25:14 EDT 2012


Hello,

I am curious if there are any tricks for tracking down the source of an interrupt. That is, the Thread which actually invoked Thread.interrupt() on some thread.  

We use a disk IO in a database with concurrent readers on a shared file. IO, of course, can be interrupted.  And when it is interrupted the backing channel is closed, so we have to jump through hoops to ensure that the channel is reopened for those threads which see the AsynchronousCloseException (or ClosedChannelException), while ensuring that the thread which sees the ClosedByInterruptException terminates its activity.

Normally I can spot the source of an interrupt by looking at the context in which the interrupt occurs and work backward through the logic of the application to figure out why the Thread might have been interrupted.  However, this is difficult when our code is embedded into other applications when we have little to know idea what else might be going on.  In particular, I am looking at an issue now where I think that the interrupt might be coming from some other component.  For example, by holding onto a Thread reference beyond the life of a worker task and then interrupting that thread.

Is it possible to somehow instrument the JVM to track and report the caller of Thread.interrupt()?  Are there profilers which can do this?  Can this be done somehow by registering a SecurityManager to log stack fames in Thread.checkAccess()?

Thanks in advance,
Bryan


More information about the Concurrency-interest mailing list