本文整理汇总了Java中java.lang.management.ThreadInfo.getLockName方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadInfo.getLockName方法的具体用法?Java ThreadInfo.getLockName怎么用?Java ThreadInfo.getLockName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.ThreadInfo
的用法示例。
在下文中一共展示了ThreadInfo.getLockName方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printThread
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void printThread(ThreadInfo ti, PrintWriter out) {
out.print("\"" + ti.getThreadName() + "\"" + " Id="
+ ti.getThreadId() + " in " + ti.getThreadState());
if (ti.getLockName() != null) {
out.print(" on lock=" + ti.getLockName());
}
if (ti.isSuspended()) {
out.print(" (suspended)");
}
if (ti.isInNative()) {
out.print(" (running in native)");
}
out.println();
if (ti.getLockOwnerName() != null) {
out.println(INDENT + " owned by " + ti.getLockOwnerName() + " Id="
+ ti.getLockOwnerId());
}
}
示例2: printThread
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static StringBuilder printThread(ThreadInfo ti, StringBuilder sb) {
sb.append("\"" + ti.getThreadName() + "\"" + " Id="
+ ti.getThreadId() + " in " + ti.getThreadState());
if (ti.getLockName() != null) {
sb.append(" waiting on lock=" + ti.getLockName());
}
if (ti.isSuspended()) {
sb.append(" (suspended)");
}
if (ti.isInNative()) {
sb.append(" (running in native)");
}
sb.append("\n");
if (ti.getLockOwnerName() != null) {
sb.append("\t owned by " + ti.getLockOwnerName() + " Id="
+ ti.getLockOwnerId()).append("\n");
}
return sb;
}
示例3: printThread
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void printThread(ThreadInfo ti, PrintStream out) {
StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + // NOI18N
" Id=" + ti.getThreadId() + // NOI18N
" in " + ti.getThreadState()); // NOI18N
if (ti.getLockName() != null) {
sb.append(" on lock=").append(ti.getLockName()); // NOI18N
}
if (ti.isSuspended()) {
sb.append(" (suspended)"); // NOI18N
}
if (ti.isInNative()) {
sb.append(" (running in native)"); // NOI18N
}
out.println(sb.toString());
if (ti.getLockOwnerName() != null) {
out.println(INDENT + " owned by " + ti.getLockOwnerName() + // NOI18N
" Id=" + ti.getLockOwnerId()); // NOI18N
}
}
示例4: print15Thread
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void print15Thread(final StringBuilder sb, final ThreadInfo thread, boolean goToSourceAvailable) {
sb.append("<br>\"" + thread.getThreadName() + // NOI18N
"\" - Thread [email protected]" + thread.getThreadId() + "<br>"); // NOI18N
sb.append(" java.lang.Thread.State: " + thread.getThreadState()); // NOI18N
if (thread.getLockName() != null) {
sb.append(" on " + thread.getLockName()); // NOI18N
if (thread.getLockOwnerName() != null) {
sb.append(" owned by: " + thread.getLockOwnerName()); // NOI18N
}
}
sb.append("<br>"); // NOI18N
for (StackTraceElement st : thread.getStackTrace()) {
String stackElementText = htmlize(st.toString());
String stackEl = stackElementText;
if (goToSourceAvailable) {
String className = st.getClassName();
String method = st.getMethodName();
int lineNo = st.getLineNumber();
String stackUrl = OPEN_THREADS_URL + className + "|" + method + "|" + lineNo; // NOI18N
stackEl = "<a href=\"" + stackUrl + "\">" + stackElementText + "</a>"; // NOI18N
}
sb.append(" at ").append(stackEl).append("<br>"); // NOI18N
}
}
示例5: getThreadInfo
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private String getThreadInfo(ThreadInfo ti) {
String message = "\"" + ti.getThreadName() + "\" [ID=" + ti.getThreadId() + "]";
message += " is " + ti.getThreadState();
if (ti.isSuspended()) {
message += " (suspended)";
}
if (ti.isInNative()) {
message += " (running in native)";
}
message += ":\n";
if (ti.getLockName() != null) {
message += INDENT + "waiting to lock " + ti.getLockName() + "\n";
}
if (ti.getLockOwnerName() != null) {
message += INDENT + "owned by \"" + ti.getLockOwnerName() + "\" [ID=" + ti.getLockOwnerId() + "]\n";
}
return message;
}
示例6: printThread
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
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());
}
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());
}
}
示例7: dumpTestThreads
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
* A debugging tool to print stack traces of most threads, as jstack does.
* Uninteresting threads are filtered out.
*/
static void dumpTestThreads() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
try {
System.setSecurityManager(null);
} catch (SecurityException giveUp) {
return;
}
}
ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
System.err.println("------ stacktrace dump start ------");
for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
final String name = info.getThreadName();
String lockName;
if ("Signal Dispatcher".equals(name))
continue;
if ("Reference Handler".equals(name)
&& (lockName = info.getLockName()) != null
&& lockName.startsWith("java.lang.ref.Reference$Lock"))
continue;
if ("Finalizer".equals(name)
&& (lockName = info.getLockName()) != null
&& lockName.startsWith("java.lang.ref.ReferenceQueue$Lock"))
continue;
if ("checkForWedgedTest".equals(name))
continue;
System.err.print(info);
}
System.err.println("------ stacktrace dump end ------");
if (sm != null) System.setSecurityManager(sm);
}
示例8: getThreadDump
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
* Formats the thread dump for one thread.
*
* @param ti
* the ThreadInfo describing the thread
* @return the formatted thread dump
*/
private static String getThreadDump(ThreadInfo ti) {
StringBuilder sb = new StringBuilder(getThreadDumpHeader(ti));
for (LockInfo li : ti.getLockedSynchronizers()) {
sb.append(INDENT2 + "locks " + li.toString() + CRLF);
}
boolean start = true;
StackTraceElement[] stes = ti.getStackTrace();
Object[] monitorDepths = new Object[stes.length];
MonitorInfo[] mis = ti.getLockedMonitors();
for (int i = 0; i < mis.length; i++) {
monitorDepths[mis[i].getLockedStackDepth()] = mis[i];
}
for (int i = 0; i < stes.length; i++) {
StackTraceElement ste = stes[i];
sb.append(INDENT2 + "at " + ste.toString() + CRLF);
if (start) {
if (ti.getLockName() != null) {
sb.append(INDENT2 + "- waiting on (a " + ti.getLockName() + ")");
if (ti.getLockOwnerName() != null) {
sb.append(" owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId());
}
sb.append(CRLF);
}
start = false;
}
if (monitorDepths[i] != null) {
MonitorInfo mi = (MonitorInfo) monitorDepths[i];
sb.append(INDENT2 + "- locked (a " + mi.toString() + ")" + " index " + mi.getLockedStackDepth()
+ " frame " + mi.getLockedStackFrame().toString());
sb.append(CRLF);
}
}
return sb.toString();
}
示例9: getThreadDump
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
* Formats the thread dump for one thread.
*
* @param ti the ThreadInfo describing the thread
* @return the formatted thread dump
*/
private static String getThreadDump(ThreadInfo ti) {
StringBuilder sb = new StringBuilder(getThreadDumpHeader(ti));
for (LockInfo li : ti.getLockedSynchronizers()) {
sb.append(INDENT2 + "locks " +
li.toString() + CRLF);
}
boolean start = true;
StackTraceElement[] stes = ti.getStackTrace();
Object[] monitorDepths = new Object[stes.length];
MonitorInfo[] mis = ti.getLockedMonitors();
for (int i = 0; i < mis.length; i++) {
monitorDepths[mis[i].getLockedStackDepth()] = mis[i];
}
for (int i = 0; i < stes.length; i++) {
StackTraceElement ste = stes[i];
sb.append(INDENT2 +
"at " + ste.toString() + CRLF);
if (start) {
if (ti.getLockName() != null) {
sb.append(INDENT2 + "- waiting on (a " +
ti.getLockName() + ")");
if (ti.getLockOwnerName() != null) {
sb.append(" owned by " + ti.getLockOwnerName() +
" Id=" + ti.getLockOwnerId());
}
sb.append(CRLF);
}
start = false;
}
if (monitorDepths[i] != null) {
MonitorInfo mi = (MonitorInfo)monitorDepths[i];
sb.append(INDENT2 +
"- locked (a " + mi.toString() + ")"+
" index " + mi.getLockedStackDepth() +
" frame " + mi.getLockedStackFrame().toString());
sb.append(CRLF);
}
}
return sb.toString();
}
示例10: checkLockInfo
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void checkLockInfo(ThreadStateController t, Thread.State state,
Object lock, Thread owner) {
ThreadInfo info = getThreadInfo(t, state);
if (info == null) {
throw new RuntimeException(t.getName() +
" expected to have ThreadInfo " +
" but got null.");
}
if (info.getThreadState() != state) {
throw new RuntimeException(t.getName() + " expected to be in " +
state + " state but got " + info.getThreadState());
}
if (lock == null && info.getLockName() != null) {
throw new RuntimeException(t.getName() +
" expected not to be blocked on any lock" +
" but got " + info.getLockName());
}
String expectedLockName = getLockName(lock);
if (lock != null && info.getLockName() == null) {
throw new RuntimeException(t.getName() +
" expected to be blocked on lock [" + expectedLockName +
"] but got null.");
}
if (lock != null && !expectedLockName.equals(info.getLockName())) {
throw new RuntimeException(t.getName() +
" expected to be blocked on lock [" + expectedLockName +
"] but got [" + info.getLockName() + "].");
}
if (owner == null && info.getLockOwnerName() != null) {
throw new RuntimeException("Lock owner is expected " +
" to be null but got " + info.getLockOwnerName());
}
if (owner != null && info.getLockOwnerName() == null) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() +
" but got null.");
}
if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() +
" but got " + owner.getName());
}
if (owner == null && info.getLockOwnerId() != -1) {
throw new RuntimeException("Lock owner is expected " +
" to be -1 but got " + info.getLockOwnerId());
}
if (owner != null && info.getLockOwnerId() <= 0) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() + "(id = " + owner.getId() +
") but got " + info.getLockOwnerId());
}
if (owner != null && info.getLockOwnerId() != owner.getId()) {
throw new RuntimeException("Lock owner is expected to be " +
owner.getName() + "(id = " + owner.getId() +
") but got " + info.getLockOwnerId());
}
if (info.isSuspended()) {
throw new RuntimeException(t.getName() +
" isSuspended() returns " + info.isSuspended());
}
}
示例11: checkThreadInfo
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
static void checkThreadInfo(ThreadInfo info) throws Exception {
if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
throw new RuntimeException("Thread Id = " + info.getThreadId() +
" expected = " + values[THREAD_ID]);
}
if (!info.getThreadName().equals(values[THREAD_NAME])) {
throw new RuntimeException("Thread Name = " +
info.getThreadName() + " expected = " + values[THREAD_NAME]);
}
if (info.getThreadState() != Thread.State.RUNNABLE) {
throw new RuntimeException("Thread Name = " +
info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
}
if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
throw new RuntimeException("blocked time = " +
info.getBlockedTime() +
" expected = " + values[BLOCKED_TIME]);
}
if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
throw new RuntimeException("blocked count = " +
info.getBlockedCount() +
" expected = " + values[BLOCKED_COUNT]);
}
if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
throw new RuntimeException("waited time = " +
info.getWaitedTime() +
" expected = " + values[WAITED_TIME]);
}
if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
throw new RuntimeException("waited count = " +
info.getWaitedCount() +
" expected = " + values[WAITED_COUNT]);
}
if (!info.getLockName().equals(values[LOCK_NAME])) {
throw new RuntimeException("Lock Name = " +
info.getLockName() + " expected = " + values[LOCK_NAME]);
}
if (info.getLockOwnerId() !=
((Long) values[LOCK_OWNER_ID]).longValue()) {
throw new RuntimeException(
"LockOwner Id = " + info.getLockOwnerId() +
" expected = " + values[LOCK_OWNER_ID]);
}
if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
throw new RuntimeException("LockOwner Name = " +
info.getLockOwnerName() + " expected = " +
values[LOCK_OWNER_NAME]);
}
checkStackTrace(info.getStackTrace());
checkLockInfo(info.getLockInfo());
}
示例12: checkThreadInfo
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
static void checkThreadInfo(ThreadInfo info) throws Exception {
if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
throw new RuntimeException("Thread Id = " + info.getThreadId() +
" expected = " + values[THREAD_ID]);
}
if (!info.getThreadName().equals(values[THREAD_NAME])) {
throw new RuntimeException("Thread Name = " +
info.getThreadName() + " expected = " + values[THREAD_NAME]);
}
if (info.getThreadState() != Thread.State.RUNNABLE) {
throw new RuntimeException("Thread Name = " +
info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
}
if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
throw new RuntimeException("blocked time = " +
info.getBlockedTime() +
" expected = " + values[BLOCKED_TIME]);
}
if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
throw new RuntimeException("blocked count = " +
info.getBlockedCount() +
" expected = " + values[BLOCKED_COUNT]);
}
if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
throw new RuntimeException("waited time = " +
info.getWaitedTime() +
" expected = " + values[WAITED_TIME]);
}
if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
throw new RuntimeException("waited count = " +
info.getWaitedCount() +
" expected = " + values[WAITED_COUNT]);
}
if (!info.getLockName().equals(values[LOCK_NAME])) {
throw new RuntimeException("Lock Name = " +
info.getLockName() + " expected = " + values[LOCK_NAME]);
}
if (info.getLockOwnerId() !=
((Long) values[LOCK_OWNER_ID]).longValue()) {
throw new RuntimeException(
"LockOwner Id = " + info.getLockOwnerId() +
" expected = " + values[LOCK_OWNER_ID]);
}
if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
throw new RuntimeException("LockOwner Name = " +
info.getLockOwnerName() + " expected = " +
values[LOCK_OWNER_NAME]);
}
if (!values[DAEMON].equals(info.isDaemon())) {
throw new RuntimeException("Daemon = " +
info.isDaemon() + " expected = " +
values[DAEMON]);
}
checkStackTrace(info.getStackTrace());
checkLockInfo(info.getLockInfo());
}
示例13: asString
import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
static String asString(ThreadInfo inf) {
StringBuilder sb = new StringBuilder();
sb.append("\"").append(inf.getThreadName()).append("\"")
.append(inf.isDaemon() ? " daemon" : "")
.append(" prio=").append(inf.getPriority())
.append(" Id=").append(inf.getThreadId())
.append(" ").append(inf.getThreadState());
if (inf.getLockName() != null) {
sb.append(" on ").append(inf.getLockName());
}
if (inf.getLockOwnerName() != null) {
sb.append(" owned by \"").append(inf.getLockOwnerName())
.append("\" Id=").append(inf.getLockOwnerId());
}
if (inf.isSuspended()) {
sb.append(" (suspended)");
}
if (inf.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
int i = 0;
StackTraceElement[] stackTrace = inf.getStackTrace();
for (; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
sb.append("\tat ").append(ste.toString());
sb.append('\n');
if (i == 0 && inf.getLockInfo() != null) {
Thread.State ts = inf.getThreadState();
switch (ts) {
case BLOCKED:
sb.append("\t- blocked on ").append(inf.getLockInfo());
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on ").append(inf.getLockInfo());
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on ").append(inf.getLockInfo());
sb.append('\n');
break;
default:
}
}
for (MonitorInfo mi : inf.getLockedMonitors()) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked ").append(mi);
sb.append('\n');
}
}
}
if (i < stackTrace.length) {
sb.append("\t...");
sb.append('\n');
}
LockInfo[] locks = inf.getLockedSynchronizers();
if (locks.length > 0) {
sb.append("\n\tNumber of locked synchronizers = ").append(locks.length);
sb.append('\n');
for (LockInfo li : locks) {
sb.append("\t- ").append(li);
sb.append('\n');
}
}
sb.append('\n');
return sb.toString();
}