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


Java ThreadMXBean.findMonitorDeadlockedThreads方法代码示例

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


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

示例1: buildDeadlockInfo

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
static String buildDeadlockInfo() {
  ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
  long[] threadIds = threadBean.findMonitorDeadlockedThreads();
  if (threadIds != null && threadIds.length > 0) {
    StringWriter stringWriter = new StringWriter();
    PrintWriter out = new PrintWriter(stringWriter);
    
    ThreadInfo[] infos = threadBean.getThreadInfo(threadIds, true, true);
    for (ThreadInfo ti : infos) {
      printThreadInfo(ti, out);
      printLockInfo(ti.getLockedSynchronizers(), out);
      out.println();
    }
    
    out.close();
    return stringWriter.toString();
  } else {
    return null;
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:21,代码来源:TimedOutTestsListener.java

示例2: findDeadlockedThreads

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
private long[] findDeadlockedThreads(ThreadMXBean mbean)
{
	// JDK 1.5 only supports the findMonitorDeadlockedThreads()
	// method, so you need to comment out the following three lines
	if (mbean.isSynchronizerUsageSupported())
	{
		return mbean.findDeadlockedThreads();
	}
	return mbean.findMonitorDeadlockedThreads();
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:11,代码来源:Debug.java

示例3: main

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    CountDownLatch prepareLatch = new CountDownLatch(2);
    AtomicInteger goLatch = new AtomicInteger(1);
    Task taskA = new Task(prepareLatch, goLatch, AnnA.class);
    Task taskB = new Task(prepareLatch, goLatch, AnnB.class);
    taskA.start();
    taskB.start();
    // wait until both threads start-up
    prepareLatch.await();
    // let them go
    goLatch.set(0);
    // obtain ThreadMXBean
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    // wait for threads to finish or dead-lock
    while (taskA.isAlive() || taskB.isAlive()) {
        // attempt to join threads
        taskA.join(500L);
        taskB.join(500L);
        // detect dead-lock
        long[] deadlockedIds = threadBean.findMonitorDeadlockedThreads();
        if (deadlockedIds != null && deadlockedIds.length > 0) {
            StringBuilder sb = new StringBuilder("deadlock detected:\n\n");
            for (ThreadInfo ti : threadBean.getThreadInfo(deadlockedIds, Integer.MAX_VALUE)) {
                sb.append(ti);
            }
            throw new IllegalStateException(sb.toString());
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:30,代码来源:AnnotationTypeDeadlockTest.java

示例4: testBug70704

import java.lang.management.ThreadMXBean; //导入方法依赖的package包/类
/**
 * Tests fix for Bug#70704 - Deadlock using UpdatableResultSet.
 * 
 * Doesn't actually test the buggy behavior since it is not verifiable since the fix for Bug#59462 (revision 385a151). However, the patch for this fix is
 * needed because the synchronization in UpdatableResultSet was dated.
 * This test makes sure there is no regression.
 * 
 * WARNING! If this test fails there is no guarantee that the JVM will remain stable and won't affect any other tests. It is imperative that this test
 * passes to ensure other tests results.
 */
public void testBug70704() throws Exception {
    for (int i = 0; i < 100; i++) {
        final Statement testStmt = this.conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
        final ResultSet testRs = testStmt.executeQuery("SELECT 1");

        ExecutorService executorService = Executors.newFixedThreadPool(2);

        executorService.submit(new Callable<Void>() {
            public Void call() throws Exception {
                testStmt.close();
                return null;
            }
        });

        executorService.submit(new Callable<Void>() {
            public Void call() throws Exception {
                testRs.close();
                return null;
            }
        });

        executorService.shutdown();
        if (!executorService.awaitTermination(2, TimeUnit.SECONDS)) {
            ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
            long[] threadIds = threadMXBean.findMonitorDeadlockedThreads();
            if (threadIds != null) {
                System.err.println("Deadlock detected!");
                ThreadInfo[] threadInfos = threadMXBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
                for (ThreadInfo ti : threadInfos) {
                    System.err.println();
                    System.err.println(ti);
                    System.err.println("Stack trace:");
                    for (StackTraceElement ste : ti.getStackTrace()) {
                        System.err.println("   " + ste);
                    }
                }
                fail("Unexpected deadlock detected. Consult system output for more details. WARNING: this failure may lead to JVM instability.");
            }
        }
    }
}
 
开发者ID:bragex,项目名称:the-vigilantes,代码行数:52,代码来源:ResultSetRegressionTest.java


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