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


Java ThreadInfo.getThreadName方法代码示例

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


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

示例1: 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
   }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:Detector.java

示例2: getAllThreadInfo

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public static List<TInfo> getAllThreadInfo(){

        List<TInfo> threads = new ArrayList<>();
        ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        long[] ids = threadBean.getAllThreadIds();
        ThreadInfo[] infos = threadBean.getThreadInfo(ids);
        for (ThreadInfo info : infos){
            long id = info.getThreadId();
            TInfo tInfo = new TInfo();
            tInfo.name = info.getThreadName();
            tInfo.id = id;
            tInfo.state = info.getThreadState();
            tInfo.cpuTime = threadBean.getThreadCpuTime(id);
            threads.add(tInfo);
        }
        Collections.sort(threads,new Comparator<TInfo>() {
            @Override
            public int compare(TInfo o1, TInfo o2) {
                return Long.compare(o2.cpuTime,o1.cpuTime);
            }
        });
        return threads;
    }
 
开发者ID:ctripcorp,项目名称:cornerstone,代码行数:24,代码来源:ThreadingManager.java

示例3: getThreadDumpHeader

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Formats the thread dump header for one thread.
 *
 * @param ti the ThreadInfo describing the thread
 * @return the formatted thread dump header
 */
private static String getThreadDumpHeader(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"");
    sb.append(" Id=" + ti.getThreadId());
    sb.append(" cpu=" + threadMXBean.getThreadCpuTime(ti.getThreadId()) +
              " ns");
    sb.append(" usr=" + threadMXBean.getThreadUserTime(ti.getThreadId()) +
              " ns");
    sb.append(" blocked " + ti.getBlockedCount() + " for " +
              ti.getBlockedTime() + " ms");
    sb.append(" waited " + ti.getWaitedCount() + " for " +
              ti.getWaitedTime() + " ms");

    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (running in native)");
    }
    sb.append(CRLF);
    sb.append(INDENT3 + "java.lang.Thread.State: " + ti.getThreadState());
    sb.append(CRLF);
    return sb.toString();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:30,代码来源:Diagnostics.java

示例4: 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;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:25,代码来源:ThreadManager.java

示例5: 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());
   }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:20,代码来源:ThreadMonitor.java

示例6: 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() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    System.err.println("------ stacktrace dump start ------");
    for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
        String name = info.getThreadName();
        if ("Signal Dispatcher".equals(name))
            continue;
        if ("Reference Handler".equals(name)
            && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
            continue;
        if ("Finalizer".equals(name)
            && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
            continue;
        System.err.print(info);
    }
    System.err.println("------ stacktrace dump end ------");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:ConcurrentAssociateTest.java

示例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() {
    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
    System.err.println("------ stacktrace dump start ------");
    for (ThreadInfo info : threadMXBean.dumpAllThreads(true, true)) {
        String name = info.getThreadName();
        if ("Signal Dispatcher".equals(name))
            continue;
        if ("Reference Handler".equals(name)
            && info.getLockName().startsWith("java.lang.ref.Reference$Lock"))
            continue;
        if ("Finalizer".equals(name)
            && info.getLockName().startsWith("java.lang.ref.ReferenceQueue$Lock"))
            continue;
        if ("process reaper".equals(name))
            continue;
        if (name != null && name.startsWith("ForkJoinPool.commonPool-worker"))
            continue;
        System.err.print(info);
    }
    System.err.println("------ stacktrace dump end ------");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:26,代码来源:Basic.java

示例8: next

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
@Override
public Object next() {
  ThreadInfo currentThread = threadInfoIterator.next();
  final NodeEndpoint endpoint = dbContext.getEndpoint();
  final long id = currentThread.getThreadId();
  return new ThreadSummary(endpoint.getAddress(),
          endpoint.getFabricPort(),
          currentThread.getThreadName(),
          currentThread.getThreadId(),
          currentThread.isInNative(),
          currentThread.isSuspended(),
          currentThread.getThreadState().name(),
          stats.getCpuTrailingAverage(id, 1),
          stats.getUserTrailingAverage(id, 1),
          NUMBER_OF_CORES,
          getStackTrace(currentThread));
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:ThreadsIterator.java

示例9: getThreadDumpHeader

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Formats the thread dump header for one thread.
 *
 * @param ti
 *            the ThreadInfo describing the thread
 * @return the formatted thread dump header
 */
private static String getThreadDumpHeader(ThreadInfo ti) {
	StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"");
	sb.append(" Id=" + ti.getThreadId());
	sb.append(" cpu=" + threadMXBean.getThreadCpuTime(ti.getThreadId()) + " ns");
	sb.append(" usr=" + threadMXBean.getThreadUserTime(ti.getThreadId()) + " ns");
	sb.append(" blocked " + ti.getBlockedCount() + " for " + ti.getBlockedTime() + " ms");
	sb.append(" waited " + ti.getWaitedCount() + " for " + ti.getWaitedTime() + " ms");

	if (ti.isSuspended()) {
		sb.append(" (suspended)");
	}
	if (ti.isInNative()) {
		sb.append(" (running in native)");
	}
	sb.append(CRLF);
	sb.append(INDENT3 + "java.lang.Thread.State: " + ti.getThreadState());
	sb.append(CRLF);
	return sb.toString();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:27,代码来源:Diagnostics.java

示例10: reportStackTrace

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
/**
 * Use exception reporter to report the stack trace of the deadlocked threads.
 * @param deadlocked 
 */
private void reportStackTrace(ThreadInfo[] deadlocked, File report) {
    DeadlockDetectedException deadlockException = new DeadlockDetectedException(null);
    deadlockException.setStackTrace(deadlocked[0].getStackTrace());
    DeadlockDetectedException lastDde = deadlockException;
    for (ThreadInfo toBeReported : deadlocked) {
        DeadlockDetectedException dde = new DeadlockDetectedException(toBeReported.getThreadName());
        dde.setStackTrace(toBeReported.getStackTrace());
        lastDde.initCause(dde);
        lastDde = dde;
    }
    LOG.log(Level.SEVERE, report.getAbsolutePath(), deadlockException);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:Detector.java

示例11: onBlockDetected

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
protected void onBlockDetected(ThreadInfo blockedThread, @Nullable ThreadInfo blockingThread) {
    String blockedThreadStackTrace = stackTrace(blockedThread.getStackTrace());
    String blockingThreadStackTrace = blockingThread != null ?
        stackTrace(blockingThread.getStackTrace()) : "not available";
    throw new AssertionError("Thread [" + blockedThread.getThreadName() + "] is blocked waiting on the resource [" +
        blockedThread.getLockInfo() + "] held by the suspended thread [" + blockedThread.getLockOwnerName() +
        "] of the disrupted node [" + disruptedNode + "].\n" +
        "Please add this occurrence to the unsafeClasses list in [" + LongGCDisruption.class.getName() + "].\n" +
        "Stack trace of blocked thread: " + blockedThreadStackTrace + "\n" +
        "Stack trace of blocking thread: " + blockingThreadStackTrace);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:12,代码来源:LongGCDisruption.java

示例12: isIdleThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static boolean isIdleThread(ThreadInfo threadInfo) {
    String threadName = threadInfo.getThreadName();

    // NOTE: these are likely JVM dependent
    if (threadName.equals("Signal Dispatcher") ||
        threadName.equals("Finalizer") ||
        threadName.equals("Reference Handler")) {
        return true;
    }

    for (StackTraceElement frame : threadInfo.getStackTrace()) {
        String className = frame.getClassName();
        String methodName = frame.getMethodName();
        if (className.equals("java.util.concurrent.ThreadPoolExecutor") &&
            methodName.equals("getTask")) {
            return true;
        }
        if (className.equals("sun.nio.ch.SelectorImpl") &&
            methodName.equals("select")) {
            return true;
        }
        if (className.equals("org.elasticsearch.threadpool.ThreadPool$EstimatedTimeThread") &&
            methodName.equals("run")) {
            return true;
        }
        if (className.equals("org.elasticsearch.indices.ttl.IndicesTTLService$Notifier") &&
            methodName.equals("await")) {
            return true;
        }
        if (className.equals("java.util.concurrent.LinkedTransferQueue") &&
            methodName.equals("poll")) {
            return true;
        }
    }

    return false;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:38,代码来源:HotThreads.java

示例13: isIdleThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private static boolean isIdleThread(ThreadInfo threadInfo) {
    String threadName = threadInfo.getThreadName();

    // NOTE: these are likely JVM dependent
    if (threadName.equals("Signal Dispatcher") ||
        threadName.equals("Finalizer") ||
        threadName.equals("Reference Handler")) {
        return true;
    }
        
    for (StackTraceElement frame : threadInfo.getStackTrace()) {
        String className = frame.getClassName();
        String methodName = frame.getMethodName();
        if (className.equals("java.util.concurrent.ThreadPoolExecutor") &&
            methodName.equals("getTask")) {
            return true;
        }
        if (className.equals("sun.nio.ch.SelectorImpl") &&
            methodName.equals("select")) {
            return true;
        }
        if (className.equals("org.elasticsearch.threadpool.ThreadPool$EstimatedTimeThread") &&
            methodName.equals("run")) {
            return true;
        }
        if (className.equals("org.elasticsearch.indices.ttl.IndicesTTLService$Notifier") &&
            methodName.equals("await")) {
            return true;
        }
        if (className.equals("java.util.concurrent.LinkedTransferQueue") &&
            methodName.equals("poll")) {
            return true;
        }
    }

    return false;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:38,代码来源:HotThreads.java

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

示例15: assertAllThreadsStopped

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
protected void assertAllThreadsStopped() throws InterruptedException {
    Set<String> failedThreads = new HashSet<>();

    int attempts = 3;

    for (int i = 0; i < attempts; i++) {
        ThreadMXBean jmx = ManagementFactory.getThreadMXBean();

        ThreadInfo[] threads = jmx.getThreadInfo(jmx.getAllThreadIds());

        for (ThreadInfo t : threads) {
            if (t != null && t.getThreadState() != Thread.State.TERMINATED) {
                String name = t.getThreadName();

                if (!FAILED_THREAD_NAMES_CACHE.contains(name)) {
                    String nameLower = name.toLowerCase();

                    if (KNOWN_THREAD_PREFIXES.stream().noneMatch(nameLower::startsWith)) {
                        failedThreads.add(name);
                    }
                }
            }
        }

        if (failedThreads.isEmpty()) {
            break;
        }

        if (i < attempts - 1) {
            failedThreads.clear();

            Thread.sleep(BUSY_WAIT_INTERVAL);
        }
    }

    if (!failedThreads.isEmpty()) {
        FAILED_THREAD_NAMES_CACHE.addAll(failedThreads);
    }

    assertTrue(failedThreads.toString(), failedThreads.isEmpty());
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:42,代码来源:HekateTestBase.java


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