当前位置: 首页>>代码示例>>Java>>正文


Java ThreadInfo.getLockedMonitors方法代码示例

本文整理汇总了Java中java.lang.management.ThreadInfo.getLockedMonitors方法的典型用法代码示例。如果您正苦于以下问题:Java ThreadInfo.getLockedMonitors方法的具体用法?Java ThreadInfo.getLockedMonitors怎么用?Java ThreadInfo.getLockedMonitors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ThreadInfo的用法示例。


在下文中一共展示了ThreadInfo.getLockedMonitors方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static StringBuilder printThreadInfo(ThreadInfo ti, StringBuilder sb) {
    // print thread information
    printThread(ti, sb);

    // print stack trace with locks
    StackTraceElement[] stacktrace = ti.getStackTrace();
    MonitorInfo[] monitors = ti.getLockedMonitors();
    for (int i = 0; i < stacktrace.length; i++) {
        StackTraceElement ste = stacktrace[i];
        sb.append("\t at " + ste.toString()).append("\n");
        for (MonitorInfo mi : monitors) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t  - locked " + mi).append("\n");
            }
        }
    }
    sb.append("\n");
    return sb;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:NbTestCase.java

示例2: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void printThreadInfo(ThreadInfo ti, PrintStream out) {
   printThread(ti, out);

   // print stack trace with locks
   StackTraceElement[] stacktrace = ti.getStackTrace();
   MonitorInfo[] monitors = ti.getLockedMonitors();
   for (int i = 0; i < stacktrace.length; i++) {
       StackTraceElement ste = stacktrace[i];
       out.println(INDENT + "at " + ste.toString()); // NOI18N
       for (MonitorInfo mi : monitors) {
           if (mi.getLockedStackDepth() == i) {
               out.println(INDENT + "  - locked " + mi); // NOI18N
           }
       }
   }
   out.println();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:Detector.java

示例3: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void printThreadInfo(ThreadInfo ti, PrintWriter out) {
  // print thread information
  printThread(ti, out);

  // print stack trace with locks
  StackTraceElement[] stacktrace = ti.getStackTrace();
  MonitorInfo[] monitors = ti.getLockedMonitors();
  for (int i = 0; i < stacktrace.length; i++) {
    StackTraceElement ste = stacktrace[i];
    out.println(INDENT + "at " + ste.toString());
    for (MonitorInfo mi : monitors) {
      if (mi.getLockedStackDepth() == i) {
        out.println(INDENT + "  - locked " + mi);
      }
    }
  }
  out.println();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:TimedOutTestsListener.java

示例4: printThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void printThreadInfo(ThreadInfo ti) {
   // print thread information
   printThread(ti);

   // print stack trace with locks
   StackTraceElement[] stacktrace = ti.getStackTrace();
   MonitorInfo[] monitors = ti.getLockedMonitors();
   for (int i = 0; i < stacktrace.length; i++) {
       StackTraceElement ste = stacktrace[i];
       System.out.println(INDENT + "at " + ste.toString());
       for (MonitorInfo mi : monitors) {
           if (mi.getLockedStackDepth() == i) {
               System.out.println(INDENT + "  - locked " + mi);
           }
       }
   }
   System.out.println();
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:ThreadMonitor.java

示例5: isMonitorLockHeldByThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public static boolean isMonitorLockHeldByThread(Object o, Thread t) {
    int oihc = System.identityHashCode(o);
    ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
    ThreadInfo[] tinfos = tmxbean.dumpAllThreads(true, false);

    for (ThreadInfo ti : tinfos) {
        if (!(t != null && t.getId() != ti.getThreadId())) {
            for (MonitorInfo mi : ti.getLockedMonitors()) {
                if (mi.getIdentityHashCode() == oihc) {
                    return true;
                }
            }
        }
    }
    return false;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:GraalOSRLockTest.java

示例6: printMonitorInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void printMonitorInfo(ThreadInfo ti, PrintStream out) {
   MonitorInfo[] monitors = ti.getLockedMonitors();
   out.println(INDENT + "Locked monitors: count = " + monitors.length); // NOI18N
   for (MonitorInfo mi : monitors) {
       out.println(INDENT + "  - " + mi + " locked at "); // NOI18N
       out.println(INDENT + "      " + mi.getLockedStackDepth() + // NOI18N
                          " " + mi.getLockedStackFrame());       // NOI18N
   }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:Detector.java

示例7: dumpThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static void dumpThread(ThreadInfo thread, Logger log, Level level)
{
    if (thread == null) return;
    if ( thread.getThreadState() != State.WAITING )
    {
        log.log( level, "------------------------------" );
        //
        log.log( level, "Current Thread: " + thread.getThreadName() );
        log.log( level, "\tPID: " + thread.getThreadId()
                + " | Suspended: " + thread.isSuspended()
                + " | Native: " + thread.isInNative()
                + " | State: " + thread.getThreadState() 
                + " | Blocked Time: " + thread.getBlockedTime()     // Cauldron add info about blocked time
                + " | Blocked Count: " + thread.getBlockedCount()); // Cauldron add info about blocked count
        
        if ( thread.getLockedMonitors().length != 0 )
        {
            log.log( level, "\tThread is waiting on monitor(s):" );
            for ( MonitorInfo monitor : thread.getLockedMonitors() )
            {
                log.log( level, "\t\tLocked on:" + monitor.getLockedStackFrame() );
            }
        }
        if ( thread.getLockOwnerId() != -1 ) log.log( level, "\tLock Owner Id: " + thread.getLockOwnerId()); // Cauldron + add info about lock owner thread id
        log.log( level, "\tStack:" );
        //
        StackTraceElement[] stack = thread.getStackTrace();
        for ( int line = 0; line < stack.length; line++ )
        {
            log.log( level, "\t\t" + stack[line].toString() );
        }
    }
}
 
开发者ID:UraniumMC,项目名称:Uranium,代码行数:34,代码来源:WatchdogThread.java

示例8: getThreadDebugData

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/** Returns an array list of debug information for all Java threads; useful for trying to diagnose the cause of odd behaviour.
 * 
 * @return An array list of debug information
 */
public static ArrayList<String> getThreadDebugData()
{
	ArrayList<String> strings = new ArrayList<String>();

	strings.add("------------------------------------------------------------");
	strings.add("Debugging information for Java virtual machine");
	ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
	for (ThreadInfo thread : threads)
	{
		if (thread.getThreadState() != State.WAITING)
		{
			strings.add("------------------------------------------------------------");
			strings.add(thread.getThreadName());
			strings.add("\tPID: " + thread.getThreadId() + " | Suspended: " + thread.isSuspended() + " | Native: " + thread.isInNative() + " | State: " + thread.getThreadState());
			if (thread.getLockedMonitors().length != 0)
			{
				strings.add("\tThread is waiting on monitor(s):");
				for (MonitorInfo monitor : thread.getLockedMonitors())
				{
					strings.add("\t\tLocked on:" + monitor.getLockedStackFrame());
				}
			}
			strings.add("\tStack trace:");

			StackTraceElement[] stack = thread.getStackTrace();
			for (int line = 0; line < stack.length; line++)
			{
				strings.add("\t\t" + stack[line].toString());
			}
		}
	}
	strings.add("------------------------------------------------------------");
	strings.add("End of debugging information");
	strings.add("------------------------------------------------------------");

	return strings;
}
 
开发者ID:PolyphasicDevTeam,项目名称:NoMoreOversleeps,代码行数:42,代码来源:DebugHandler.java

示例9: printMonitorInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void printMonitorInfo(ThreadInfo ti) {
   MonitorInfo[] monitors = ti.getLockedMonitors();
   System.out.println(INDENT + "Locked monitors: count = " + monitors.length);
   for (MonitorInfo mi : monitors) {
       System.out.println(INDENT + "  - " + mi + " locked at ");
       System.out.println(INDENT + "      " + mi.getLockedStackDepth() +
                          " " + mi.getLockedStackFrame());
   }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:10,代码来源:ThreadMonitor.java

示例10: generateThreadStack

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private String generateThreadStack(ThreadInfo info) {
  // This is annoying, but the to string method on info sucks.
  StringBuilder result = new StringBuilder();
  result.append(info.getThreadName()).append(" ID=0x")
      .append(Long.toHexString(info.getThreadId())).append("(").append(info.getThreadId())
      .append(") state=").append(info.getThreadState());


  if (info.getLockInfo() != null) {
    result.append("\n\twaiting to lock <" + info.getLockInfo() + ">");
  }
  for (StackTraceElement element : info.getStackTrace()) {
    result.append("\n\tat " + element);
    for (MonitorInfo monitor : info.getLockedMonitors()) {
      if (element.equals(monitor.getLockedStackFrame())) {
        result.append("\n\tlocked <" + monitor + ">");
      }
    }
  }

  if (info.getLockedSynchronizers().length > 0) {
    result.append("\nLocked synchronizers:");
    for (LockInfo sync : info.getLockedSynchronizers()) {
      result.append(
          "\n" + sync.getClassName() + "@" + Integer.toHexString(sync.getIdentityHashCode()));

    }
  }

  return result.toString();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:32,代码来源:LocalThread.java

示例11: 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();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:43,代码来源:Diagnostics.java

示例12: print16Thread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void print16Thread(final StringBuilder sb, final ThreadInfo thread, boolean goToSourceAvailable) {
    MonitorInfo[] monitors = thread.getLockedMonitors();
    sb.append("&nbsp;<b>");   // NOI18N
    sb.append("\"").append(thread.getThreadName()).append("\" - Thread [email protected]").append(thread.getThreadId()).append("<br>");    // NOI18N
    sb.append("    java.lang.Thread.State: ").append(thread.getThreadState()); // NOI18N
    sb.append("</b><br>");   // NOI18N
    int index = 0;
    for (StackTraceElement st : thread.getStackTrace()) {
        LockInfo lock = thread.getLockInfo();
        String stackElementText = htmlize(st.toString());
        String lockOwner = thread.getLockOwnerName();

        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
        if (index == 0) {
            if ("java.lang.Object".equals(st.getClassName()) && // NOI18N
                    "wait".equals(st.getMethodName())) {                // NOI18N
                if (lock != null) {
                    sb.append("    - waiting on ");    // NOI18N
                    printLock(sb, lock);
                    sb.append("<br>");    // NOI18N
                }
            } else if (lock != null) {
                if (lockOwner == null) {
                    sb.append("    - parking to wait for ");      // NOI18N
                    printLock(sb, lock);
                    sb.append("<br>");            // NOI18N
                } else {
                    sb.append("    - waiting to lock ");      // NOI18N
                    printLock(sb, lock);
                    sb.append(" owned by \"").append(lockOwner).append("\" [email protected]").append(thread.getLockOwnerId()).append("<br>");   // NOI18N
                }
            }
        }
        printMonitors(sb, monitors, index);
        index++;
    }
    StringBuilder jnisb = new StringBuilder();
    printMonitors(jnisb, monitors, -1);
    if (jnisb.length() > 0) {
        sb.append("   JNI locked monitors:<br>");
        sb.append(jnisb);
    }
    LockInfo[] synchronizers = thread.getLockedSynchronizers();
    if (synchronizers != null) {
        sb.append("<br>   Locked ownable synchronizers:");    // NOI18N
        if (synchronizers.length == 0) {
            sb.append("<br>    - None\n");  // NOI18N
        } else {
            for (LockInfo li : synchronizers) {
                sb.append("<br>    - locked ");         // NOI18N
                printLock(sb, li);
                sb.append("<br>");  // NOI18N
            }
        }
    }
    sb.append("<br>");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:ThreadDumpWindow.java

示例13: print16Thread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private void print16Thread(final StringBuilder sb, final ThreadInfo thread, boolean goToSourceAvailable) {
    MonitorInfo[] monitors = thread.getLockedMonitors();
    sb.append("&nbsp;<b>");   // NOI18N
    sb.append("\"").append(thread.getThreadName()).append("\" - Thread [email protected]").append(thread.getThreadId()).append("<br>");    // NOI18N
    sb.append("    java.lang.Thread.State: ").append(thread.getThreadState()); // NOI18N
    sb.append("</b><br>");   // NOI18N
    int index = 0;
    for (StackTraceElement st : thread.getStackTrace()) {
        LockInfo lock = thread.getLockInfo();
        String stackElementText = htmlize(st.toString());
        String lockOwner = thread.getLockOwnerName();
        String className = st.getClassName();
        String method = st.getMethodName();
        int lineNo = st.getLineNumber();
        
        String stackEl = stackElementText;
        if (goToSourceAvailable) {
            String stackUrl = OPEN_THREADS_URL+className+"|"+method+"|"+lineNo; // NOI18N
            stackEl = "<a href=\""+stackUrl+"\">"+stackElementText+"</a>";    // NOI18N
        }

        sb.append("\tat ").append(stackEl).append("<br>");    // NOI18N
        if (index == 0) {
            if ("java.lang.Object".equals(st.getClassName()) &&     // NOI18N
                    "wait".equals(st.getMethodName())) {                // NOI18N
                if (lock != null) {
                    sb.append("\t- waiting on ");    // NOI18N
                    printLock(sb,lock);
                    sb.append("<br>");    // NOI18N
                }
            } else if (lock != null) {
                if (lockOwner == null) {
                    sb.append("\t- parking to wait for ");      // NOI18N
                    printLock(sb,lock);
                    sb.append("<br>");            // NOI18N
                } else {
                    sb.append("\t- waiting to lock ");      // NOI18N
                    printLock(sb,lock);
                    sb.append(" owned by \"").append(lockOwner).append("\" [email protected]").append(thread.getLockOwnerId()).append("<br>");   // NOI18N
                }
            }
        }
        printMonitors(sb, monitors, index);
        index++;
    }
    StringBuilder jnisb = new StringBuilder();
    printMonitors(jnisb, monitors, -1);
    if (jnisb.length() > 0) {
        sb.append("   JNI locked monitors:<br>");
        sb.append(jnisb);
    }
    LockInfo[] synchronizers = thread.getLockedSynchronizers();
    if (synchronizers != null) {
        sb.append("<br>   Locked ownable synchronizers:");    // NOI18N
        if (synchronizers.length == 0) {
            sb.append("<br>\t- None\n");  // NOI18N
        } else {
            for (LockInfo li : synchronizers) {
                sb.append("<br>\t- locked ");         // NOI18N
                printLock(sb,li);
                sb.append("<br>");  // NOI18N
            }
        }
    }
    sb.append("<br>");
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:67,代码来源:SampledCPUSnapshot.java

示例14: 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();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:48,代码来源:Diagnostics.java

示例15: 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();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:71,代码来源:TestConfigurationLock.java


注:本文中的java.lang.management.ThreadInfo.getLockedMonitors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。