當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。