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

前端 未结 5 880
清酒与你
清酒与你 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条回答
  •  萌比男神i
    2021-02-06 12:51

    You could try also with JMX:

    ManagementFactory.getThreadMXBean().getThreadInfo(aThreadID)
    

    with the ThreadInfo object you can log:

    • the stack trace of the thread
    • general userful information like name, status, etc
    • etc

    EDIT

    use getAllThreadIds() in order to obtain the list of live thread ids:

    long[] ids = ManagementFactory.getThreadMXBean().getAllThreadIds();
    

提交回复
热议问题