[concurrency-interest] Concurrency-interest Digest, Vol 86, Issue 18

Yakov Zhdanov yakov.zhdanov at gmail.com
Thu Mar 29 01:48:35 EDT 2012


You may also override interrupt() this way:

        @Override public void interrupt() {
            // Get full stack on interruption.
            new Exception().printStackTrace();

            super.interrupt();
        }

Yakov


2012/3/28 <concurrency-interest-request at cs.oswego.edu>

> Send Concurrency-interest mailing list submissions to
>        concurrency-interest at cs.oswego.edu
>
> To subscribe or unsubscribe via the World Wide Web, visit
>        http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> or, via email, send a message with subject or body 'help' to
>        concurrency-interest-request at cs.oswego.edu
>
> You can reach the person managing the list at
>        concurrency-interest-owner at cs.oswego.edu
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Concurrency-interest digest..."
>
>
> Today's Topics:
>
>   1. Re: Advice on tracking down the caller of Thread.interrupt()?
>      (Bryan Thompson)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 27 Mar 2012 13:33:53 -0500
> From: Bryan Thompson <bryan at systap.com>
> To: "concurrency-interest at cs.oswego.edu"
>        <concurrency-interest at cs.oswego.edu>
> Subject: Re: [concurrency-interest] Advice on tracking down the caller
>        of Thread.interrupt()?
> Message-ID:
>        <
> DE10B00CCE0DC54883734F3060AC9ED46739FF0AE0 at AUSP01VMBX06.collaborationhost.net
> >
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Thanks to everyone who wrote back on this.  One other suggestion (off
> list) was that Thread.interrupt() is not final.   You can specialize the
> thread pool factory and override Thread.interrupt to report the Thread
> which triggered the interrupt.
>
> Thanks again,
> Bryan
>
> > -----Original Message-----
> > From: concurrency-interest-bounces at cs.oswego.edu
> > [mailto:concurrency-interest-bounces at cs.oswego.edu] On Behalf
> > Of R?mi Forax
> > Sent: Wednesday, March 21, 2012 4:01 PM
> > To: concurrency-interest at cs.oswego.edu
> > Subject: Re: [concurrency-interest] Advice on tracking down
> > the caller of Thread.interrupt()?
> >
> > On 03/21/2012 08:25 PM, Bryan Thompson wrote:
> > > 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
> >
> > You can do it by yourself, it's not hard :)
> >
> >  From the directory that contains all JDK files, find the
> > src.zip, which is roughly a zip of the source of the public
> > classes of the JDK.
> > Extract java/lang/Thread.java
> > Now, as you can see Thread::interrupt() is written in Java,
> > so you can add all the instructions you want :) To get the
> > caller class, use sun.reflect.reflection.getCallerClass(2)
> > (see [1]),
> > because you are in a trusted class, you can call it.
> > Compile your class and prepend it in front of the
> > bootclasspath, so your classwill be loaded instead of the one
> > from rt.jar (see java -X and java -Xbootclasspath/p )
> >
> > cheers,
> > R?mi
> >
> > [1]
> > http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/tip/src/share/cl
> > asses/sun/reflect/Reflection.java
> >
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at cs.oswego.edu
> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> >
>
>
> ------------------------------
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
>
> End of Concurrency-interest Digest, Vol 86, Issue 18
> ****************************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20120329/751d832a/attachment.html>


More information about the Concurrency-interest mailing list