List of usage examples for java.lang.management ThreadInfo getBlockedCount
public long getBlockedCount()
From source file:com.thoughtworks.go.server.service.support.ThreadInformationProvider.java
private TreeMap<Long, Map<String, Object>> getStackTraceInformation(ThreadMXBean threadMXBean) { TreeMap<Long, Map<String, Object>> traces = new TreeMap<>(); ThreadInfo[] threadInfos = threadMXBean.dumpAllThreads(true, true); for (ThreadInfo threadInfo : threadInfos) { LinkedHashMap<String, Object> threadStackTrace = new LinkedHashMap<>(); threadStackTrace.put("Id", threadInfo.getThreadId()); threadStackTrace.put("Name", threadInfo.getThreadName()); threadStackTrace.put("State", threadInfo.getThreadState()); LinkedHashMap<String, Object> lockMonitorInfo = new LinkedHashMap<>(); MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors(); ArrayList<Map<String, Object>> lockedMonitorsJson = new ArrayList<>(); for (MonitorInfo lockedMonitor : lockedMonitors) { LinkedHashMap<String, Object> lockedMonitorJson = new LinkedHashMap<>(); lockedMonitorJson.put("Class", lockedMonitor.getClassName()); lockedMonitorJson.put("IdentityHashCode", lockedMonitor.getIdentityHashCode()); lockedMonitorJson.put("LockedStackDepth", lockedMonitor.getLockedStackDepth()); lockedMonitorJson.put("StackFrame", lockedMonitor.getLockedStackFrame().toString()); lockedMonitorsJson.add(lockedMonitorJson); }//from w w w. j a va2 s .c o m lockMonitorInfo.put("Locked Monitors", lockedMonitorsJson); lockMonitorInfo.put("Locked Synchronizers", asJSON(threadInfo.getLockedSynchronizers())); threadStackTrace.put("Lock Monitor Info", lockMonitorInfo); LinkedHashMap<String, Object> blockedInfo = new LinkedHashMap<>(); blockedInfo.put("Blocked Time", threadInfo.getBlockedTime() == -1 ? null : threadInfo.getBlockedTime()); blockedInfo.put("Blocked Count", threadInfo.getBlockedCount()); threadStackTrace.put("Blocked Info", blockedInfo); LinkedHashMap<String, Object> timeInfo = new LinkedHashMap<>(); timeInfo.put("Waited Time", threadInfo.getWaitedTime() == -1 ? null : threadInfo.getWaitedTime()); timeInfo.put("Waited Count", threadInfo.getWaitedCount()); threadStackTrace.put("Time Info", timeInfo); LinkedHashMap<String, Object> lockInfoMap = new LinkedHashMap<>(); LockInfo lockInfo = threadInfo.getLockInfo(); lockInfoMap.put("Locked On", asJSON(lockInfo)); lockInfoMap.put("Lock Owner Thread Id", threadInfo.getLockOwnerId() == -1 ? null : threadInfo.getLockOwnerId()); lockInfoMap.put("Lock Owner Thread Name", threadInfo.getLockOwnerName()); threadStackTrace.put("Lock Info", lockInfoMap); LinkedHashMap<String, Object> stateInfo = new LinkedHashMap<>(); stateInfo.put("Suspended", threadInfo.isSuspended()); stateInfo.put("InNative", threadInfo.isInNative()); threadStackTrace.put("State Info", stateInfo); threadStackTrace.put("Stack Trace", asJSON(threadInfo.getStackTrace())); traces.put(threadInfo.getThreadId(), threadStackTrace); } return traces; }
From source file:org.apache.hadoop.hbase.util.ReflectionUtils.java
/** * Print all of the thread's information and stack traces. * * @param stream the stream to//from w w w . ja va 2s . c o m * @param title a string title for the stack trace */ private static void printThreadInfo(PrintStream stream, String title) { final int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: " + title); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; } stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state); stream.println(" Blocked count: " + info.getBlockedCount()); stream.println(" Waited count: " + info.getWaitedCount()); if (contention) { stream.println(" Blocked time: " + info.getBlockedTime()); stream.println(" Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } } stream.flush(); }
From source file:org.apache.hadoop.util.ReflectionUtils.java
/** * Print all of the thread's information and stack traces. * * @param stream the stream to//w w w.j a va2s . co m * @param title a string title for the stack trace */ public static synchronized void printThreadInfo(PrintWriter stream, String title) { final int stackDepth = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: " + title); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, stackDepth); if (info == null) { stream.println(" Inactive"); continue; } stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state); stream.println(" Blocked count: " + info.getBlockedCount()); stream.println(" Waited count: " + info.getWaitedCount()); if (contention) { stream.println(" Blocked time: " + info.getBlockedTime()); stream.println(" Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } } stream.flush(); }
From source file:org.apache.hama.util.ReflectionUtils.java
/** * Print all of the thread's information and stack traces. * /*from w w w .j av a 2 s . c o m*/ * @param stream the stream to * @param title a string title for the stack trace */ public synchronized static void printThreadInfo(PrintWriter stream, String title) { final int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: " + title); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; } stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state); stream.println(" Blocked count: " + info.getBlockedCount()); stream.println(" Waited count: " + info.getWaitedCount()); if (contention) { stream.println(" Blocked time: " + info.getBlockedTime()); stream.println(" Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } } stream.flush(); }
From source file:org.apache.tajo.master.querymaster.QueryMasterRunner.java
public static void printThreadInfo(PrintWriter stream, String title) { ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); final int STACK_DEPTH = 60; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: " + title); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; }/*from w w w . j a v a 2 s . co m*/ stream.println("Thread " + getTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state); stream.println(" Blocked count: " + info.getBlockedCount()); stream.println(" Waited count: " + info.getWaitedCount()); if (contention) { stream.println(" Blocked time: " + info.getBlockedTime()); stream.println(" Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName()); stream.println(" Blocked by " + getTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } } stream.flush(); }
From source file:org.apache.tajo.master.TajoMaster.java
public void dumpThread(Writer writer) { PrintWriter stream = new PrintWriter(writer); int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: Tajo Worker"); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; }//w w w. ja v a 2s .com stream.println("Thread " + getThreadTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state + ", Blocked count: " + info.getBlockedCount() + ", Waited count: " + info.getWaitedCount()); if (contention) { stream.println( " Blocked time: " + info.getBlockedTime() + ", Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName() + ", Blocked by " + getThreadTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } stream.println(""); } }
From source file:org.apache.tajo.worker.TajoWorker.java
public void dumpThread(Writer writer) { PrintWriter stream = new PrintWriter(writer); int STACK_DEPTH = 20; boolean contention = threadBean.isThreadContentionMonitoringEnabled(); long[] threadIds = threadBean.getAllThreadIds(); stream.println("Process Thread Dump: Tajo Worker"); stream.println(threadIds.length + " active threads"); for (long tid : threadIds) { ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH); if (info == null) { stream.println(" Inactive"); continue; }/* ww w . j a va 2 s . c o m*/ stream.println("Thread " + getThreadTaskName(info.getThreadId(), info.getThreadName()) + ":"); Thread.State state = info.getThreadState(); stream.println(" State: " + state + ", Blocked count: " + info.getBlockedCount() + ", Waited count: " + info.getWaitedCount()); if (contention) { stream.println( " Blocked time: " + info.getBlockedTime() + ", Waited time: " + info.getWaitedTime()); } if (state == Thread.State.WAITING) { stream.println(" Waiting on " + info.getLockName()); } else if (state == Thread.State.BLOCKED) { stream.println(" Blocked on " + info.getLockName() + ", Blocked by " + getThreadTaskName(info.getLockOwnerId(), info.getLockOwnerName())); } stream.println(" Stack:"); for (StackTraceElement frame : info.getStackTrace()) { stream.println(" " + frame.toString()); } stream.println(""); } }