Is there any way in Java to log *every* Thread interrupt?

前端 未结 5 804
清酒与你
清酒与你 2021-02-06 12:11

I would like to somehow log every time Thread.interrupt() is called, logging which Thread issued the call (and its current stack) as well as identifying information

5条回答
  •  日久生厌
    2021-02-06 12:53

    As others have said... If it is a one-time thing JVMTI is probably the most hardcore way to go. However, just as fun could be to use the asm library and the instrumentation APIs to create an agent that inserts a call to a static method you've created just before the Thread.interrupt() call (or maybe alters the Thread.interrupt() method to do the same, I think you can do that).

    Both takes some time to learn but it is quite fun to work with and once you get the hold of it you can use them for all kinds of funny things in the future :-) I don't really have any good snippets to paste here right now but if you google around for ASM and maybe look at the JIP for some creative use of ASM I think you will find inspiration.

    JIP: Java Interactive Profiler

提交回复
热议问题