Java tutorial
//package com.java2s; //License from project: Apache License import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.management.ThreadMXBean; public class Main { public static String getThreadHeadline(long threadID) { ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean(); ThreadInfo threadInfo = threadMXBean.getThreadInfo(threadID, Integer.MAX_VALUE); return getThreadHeadline(threadInfo); } public static String getThreadHeadline(ThreadInfo threadInfo) { String buf = "\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState(); if (threadInfo.getLockName() != null) { buf += " on " + threadInfo.getLockName(); } if (threadInfo.getLockOwnerName() != null) { buf += " owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId(); } if (threadInfo.isSuspended()) { buf += " (suspended)"; } if (threadInfo.isInNative()) { buf += " (in native)"; } return buf; } }