List of usage examples for java.lang.management ThreadInfo isInNative
public boolean isInNative()
From source file:Main.java
private static String getThreadHead(ThreadInfo f) { StringBuffer sb = new StringBuffer(); sb.append('"').append(f.getThreadName()).append('"'); sb.append(" tid=0x" + Long.toHexString(f.getThreadId())); sb.append(" native=" + f.isInNative()); sb.append(" suspended=" + f.isSuspended()); return sb.toString(); }
From source file:Main.java
/** Builds the stack traces of all the given ThreadInfos in the buffer. Returns the stack trace of the first thread. */ private static StackTraceElement[] buildTrace(ThreadInfo[] allThreadInfo, StringBuilder buffer) { StackTraceElement[] firstStackTrace = null; for (ThreadInfo info : allThreadInfo) { buffer.append("\"" + info.getThreadName() + "\" (id=" + info.getThreadId() + ")"); buffer.append(" " + info.getThreadState() + " on " + info.getLockName() + " owned by "); buffer.append("\"" + info.getLockOwnerName() + "\" (id=" + info.getLockOwnerId() + ")"); if (info.isSuspended()) buffer.append(" (suspended)"); if (info.isInNative()) buffer.append(" (in native)"); buffer.append("\n"); StackTraceElement[] trace = info.getStackTrace(); if (firstStackTrace == null) firstStackTrace = trace;/*ww w . j av a 2s .c o m*/ for (int i = 0; i < trace.length; i++) { buffer.append("\tat " + trace[i].toString() + "\n"); if (i == 0) addLockInfo(info, buffer); addMonitorInfo(info, buffer, i); } addLockedSynchronizers(info, buffer); buffer.append("\n"); } return firstStackTrace; }
From source file:Main.java
public static void printThreadInfo(ThreadInfo info, StringBuilder builder) { builder.append("Thread ").append(info.getThreadName()).append("\" (").append(info.getThreadId()) .append(") -- "); formatState(builder, info);//from w ww . j a v a 2s . c om if (info.isSuspended()) { builder.append(" (suspended)"); } if (info.isInNative()) { builder.append(" (in native)"); } builder.append("\n"); // The waited lock. LockInfo li = info.getLockInfo(); if (li != null) { builder.append("Waiting for "); formatLock(builder, li); if (info.getLockOwnerName() != null) { builder.append(" owned by ").append(info.getLockOwnerName()).append("(") .append(info.getLockOwnerId()).append(")"); } builder.append("\n"); } // The stack builder.append("Stack:\n"); printStack(info, builder, getStackForThread(info.getThreadId())); }
From source file:Main.java
public static String getThreadHeadline(ThreadInfo threadInfo) { String buf = "\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState(); if (threadInfo.getLockName() != null) { buf += " on " + threadInfo.getLockName(); }/*from www. java 2 s . com*/ 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; }
From source file:Main.java
/** * Turns the given {@link ThreadInfo} into a {@link String}. *//*from w ww .j a v a 2s .c om*/ public static String toString(ThreadInfo[] threads) { StringBuilder buffer = new StringBuilder(); for (ThreadInfo info : threads) { buffer.append("\"").append(info.getThreadName()).append("\" (id=").append(info.getThreadId()) .append(")"); buffer.append(" ").append(info.getThreadState()).append(" on ").append(info.getLockName()) .append(" owned by "); buffer.append("\"").append(info.getLockOwnerName()).append("\" (id=").append(info.getLockOwnerId()) .append(")"); if (info.isSuspended()) { buffer.append(" (suspended)"); } if (info.isInNative()) { buffer.append(" (is native)"); } buffer.append("\n"); StackTraceElement[] trace = info.getStackTrace(); for (int i = 0; i < trace.length; i++) { buffer.append("\tat ").append(trace[i]).append("\n"); if (i == 0) { buffer.append(getLockState(info)); } buffer.append(getLockedMonitors(info, i)); } buffer.append("\n"); } return buffer.toString(); }
From source file:Main.java
static public String toString(ThreadInfo threadInfo) { StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState()); if (threadInfo.getLockName() != null) { sb.append(" on " + threadInfo.getLockName()); }/*from w w w.j a va2s . c o m*/ if (threadInfo.getLockOwnerName() != null) { sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId()); } if (threadInfo.isSuspended()) { sb.append(" (suspended)"); } if (threadInfo.isInNative()) { sb.append(" (in native)"); } sb.append('\n'); int i = 0; StackTraceElement[] stackTrace = threadInfo.getStackTrace(); for (StackTraceElement ste : stackTrace) { // for (; i < threadInfo.getStackTrace().length && i < 64; i++) { // StackTraceElement ste = stackTrace[i]; sb.append("\tat " + ste.toString()); sb.append('\n'); if (i == 0 && threadInfo.getLockInfo() != null) { Thread.State ts = threadInfo.getThreadState(); switch (ts) { case BLOCKED: sb.append("\t- blocked on " + threadInfo.getLockInfo()); sb.append('\n'); break; case WAITING: sb.append("\t- waiting on " + threadInfo.getLockInfo()); sb.append('\n'); break; case TIMED_WAITING: sb.append("\t- waiting on " + threadInfo.getLockInfo()); sb.append('\n'); break; default: } } for (MonitorInfo mi : threadInfo.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t- locked " + mi); sb.append('\n'); } } } if (i < stackTrace.length) { sb.append("\t..."); sb.append('\n'); } LockInfo[] locks = threadInfo.getLockedSynchronizers(); if (locks.length > 0) { sb.append("\n\tNumber of locked synchronizers = " + locks.length); sb.append('\n'); for (LockInfo li : locks) { sb.append("\t- " + li); sb.append('\n'); } } sb.append('\n'); return sb.toString(); }
From source file:Main.java
private static void threadHeader(StringBuilder sb, ThreadInfo threadInfo) { final String threadName = threadInfo.getThreadName(); sb.append("\""); sb.append(threadName);// w ww . ja v a 2 s. c om sb.append("\" "); sb.append("Id="); sb.append(threadInfo.getThreadId()); try { final Thread.State threadState = threadInfo.getThreadState(); final String lockName = threadInfo.getLockName(); final String lockOwnerName = threadInfo.getLockOwnerName(); final Long lockOwnerId = threadInfo.getLockOwnerId(); final Boolean isSuspended = threadInfo.isSuspended(); final Boolean isInNative = threadInfo.isInNative(); sb.append(" "); sb.append(threadState); if (lockName != null) { sb.append(" on "); sb.append(lockName); } if (lockOwnerName != null) { sb.append(" owned by \""); sb.append(lockOwnerName); sb.append("\" Id="); sb.append(lockOwnerId); } if (isSuspended) { sb.append(" (suspended)"); } if (isInNative) { sb.append(" (in native)"); } } catch (final Exception e) { sb.append(" ( Got exception : ").append(e.getMessage()).append(" :"); } sb.append('\n'); }
From source file:Main.java
private static String threadInfoToString(ThreadInfo threadInfo) { StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState()); if (threadInfo.getLockName() != null) { sb.append(" on " + threadInfo.getLockName()); }/*from w ww .jav a 2 s . c om*/ if (threadInfo.getLockOwnerName() != null) { sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId()); } if (threadInfo.isSuspended()) { sb.append(" (suspended)"); } if (threadInfo.isInNative()) { sb.append(" (in native)"); } sb.append('\n'); int i = 0; for (; i < threadInfo.getStackTrace().length; i++) { StackTraceElement ste = threadInfo.getStackTrace()[i]; sb.append("\tat " + ste.toString()); sb.append('\n'); if (i == 0 && threadInfo.getLockInfo() != null) { Thread.State ts = threadInfo.getThreadState(); switch (ts) { case BLOCKED: sb.append("\t- blocked on " + threadInfo.getLockInfo()); sb.append('\n'); break; case WAITING: sb.append("\t- waiting on " + threadInfo.getLockInfo()); sb.append('\n'); break; case TIMED_WAITING: sb.append("\t- waiting on " + threadInfo.getLockInfo()); sb.append('\n'); break; default: } } for (MonitorInfo mi : threadInfo.getLockedMonitors()) { if (mi.getLockedStackDepth() == i) { sb.append("\t- locked " + mi); sb.append('\n'); } } } LockInfo[] locks = threadInfo.getLockedSynchronizers(); if (locks.length > 0) { sb.append("\n\tNumber of locked synchronizers = " + locks.length); sb.append('\n'); for (LockInfo li : locks) { sb.append("\t- " + li); sb.append('\n'); } } sb.append('\n'); return sb.toString(); }
From source file:DeadlockDetector.java
private void printThread(ThreadInfo ti) { sb.append("\nPrintThread\n"); sb.append(/*from ww w . ja v a2 s.co m*/ "\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState() + "\n"); if (ti.getLockName() != null) { sb.append(" on lock=" + ti.getLockName() + "\n"); } if (ti.isSuspended()) { sb.append(" (suspended)" + "\n"); } if (ti.isInNative()) { sb.append(" (running in native)" + "\n"); } if (ti.getLockOwnerName() != null) { sb.append(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId() + "\n"); } }
From source file:FullThreadDump.java
private void printThread(ThreadInfo ti) { StringBuilder sb = new StringBuilder( "\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState()); if (ti.getLockName() != null) { sb.append(" on lock=" + ti.getLockName()); }/*from ww w . j a v a2 s .c o m*/ if (ti.isSuspended()) { sb.append(" (suspended)"); } if (ti.isInNative()) { sb.append(" (running in native)"); } System.out.println(sb.toString()); if (ti.getLockOwnerName() != null) { System.out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId()); } }