package hozza.network.security.threading.deadlock;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

public class DeadlockMonitorTask implements Runnable
{

    @Override
    public void run() {
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        long[] ids = bean.findMonitorDeadlockedThreads();

        if(ids != null)
        {
            ThreadInfo[] threadInfo = bean.getThreadInfo(ids);

            for (ThreadInfo threadInfo1 : threadInfo)
            {
                System.out.println(threadInfo1.getThreadId());    

                System.out.println(threadInfo1.getThreadName());  

                System.out.println(threadInfo1.getLockName());    

                System.out.println(threadInfo1.getLockOwnerId()); 

                System.out.println(threadInfo1.getLockOwnerName());
            }
        }
        
    }
    
}