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


Java ThreadInfo.getThreadId方法代码示例

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


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

示例4: 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

示例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: 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

示例7: writeSample

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
void writeSample(ThreadInfo[] infos, long time, long selfThreadId) throws IOException {
    List<Long> sameT = new ArrayList();
    List<ThreadInfo> newT = new ArrayList();
    List<Long> tids = new ArrayList();

    for (ThreadInfo tinfo : infos) {
        long id;

        if (tinfo == null) continue;    // ignore null ThreadInfo
        id = tinfo.getThreadId();
        if (id != selfThreadId) { // ignore sampling thread
            Long tid = Long.valueOf(tinfo.getThreadId());
            ThreadInfo lastThread = lastThreadInfos.get(tid);

            tids.add(tid);
            if (lastThread != null) {
                if (lastThread.getThreadState().equals(tinfo.getThreadState())) {
                    StackTraceElement[] lastStack = lastThread.getStackTrace();
                    StackTraceElement[] stack = tinfo.getStackTrace();

                    if (Arrays.deepEquals(lastStack, stack)) {
                        sameT.add(tid);
                        continue;
                    }
                }
            }
            internStackTrace(tinfo);
            newT.add(tinfo);
            lastThreadInfos.put(tid, tinfo);
        }
    }
    addSample(new Sample(time, sameT, newT));
    // remove dead threads
    Set<Long> ids = new HashSet(lastThreadInfos.keySet());
    ids.removeAll(tids);
    lastThreadInfos.keySet().removeAll(ids);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:38,代码来源:SamplesOutputStream.java

示例8: findMatchingThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
private Thread findMatchingThread(ThreadInfo inf)
{
	for (Thread thread : Thread.getAllStackTraces().keySet())
	{
		if (thread.getId() == inf.getThreadId())
		{
			return thread;
		}
	}
	throw new IllegalStateException("Deadlocked Thread not found");
}
 
开发者ID:rubenswagner,项目名称:L2J-Global,代码行数:12,代码来源:Debug.java

示例9: run

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public void run()
{
    while (this.server.isServerRunning())
    {
        long i = this.server.getCurrentTime();
        long j = MinecraftServer.getCurrentTimeMillis();
        long k = j - i;

        if (k > this.maxTickTime)
        {
            LOGGER.fatal("A single server tick took " + String.format("%.2f", new Object[] {Float.valueOf((float)k / 1000.0F)}) + " seconds (should be max " + String.format("%.2f", new Object[] {Float.valueOf(0.05F)}) + ")");
            LOGGER.fatal("Considering it to be crashed, server will forcibly shutdown.");
            ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
            ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
            StringBuilder stringbuilder = new StringBuilder();
            Error error = new Error();

            for (ThreadInfo threadinfo : athreadinfo)
            {
                if (threadinfo.getThreadId() == this.server.getServerThread().getId())
                {
                    error.setStackTrace(threadinfo.getStackTrace());
                }

                stringbuilder.append((Object)threadinfo);
                stringbuilder.append("\n");
            }

            CrashReport crashreport = new CrashReport("Watching Server", error);
            this.server.addServerInfoToCrashReport(crashreport);
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Thread Dump");
            crashreportcategory.addCrashSection("Threads", stringbuilder);
            File file1 = new File(new File(this.server.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");

            if (crashreport.saveToFile(file1))
            {
                LOGGER.error("This crash report has been saved to: " + file1.getAbsolutePath());
            }
            else
            {
                LOGGER.error("We were unable to save this crash report to disk.");
            }

            this.scheduleHalt();
        }

        try
        {
            Thread.sleep(i + this.maxTickTime - j);
        }
        catch (InterruptedException var15)
        {
            ;
        }
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:57,代码来源:ServerHangWatchdog.java

示例10: LocalThread

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public LocalThread(Serializable locatility, ThreadInfo info) {
  this.locality = locatility;
  this.threadName = info.getThreadName();
  this.threadStack = generateThreadStack(info);
  this.threadId = info.getThreadId();
}
 
开发者ID:ampool,项目名称:monarch,代码行数:7,代码来源:LocalThread.java

示例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());
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:54,代码来源:ThreadInfoCompositeData.java

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

示例13: run

import java.lang.management.ThreadInfo; //导入方法依赖的package包/类
public void run()
{
    while (this.server.isServerRunning())
    {
        long i = this.server.getCurrentTime();
        long j = MinecraftServer.getCurrentTimeMillis();
        long k = j - i;

        if (k > this.maxTickTime && !this.firstRun)
        {
            LOGGER.fatal("A single server tick took {} seconds (should be max {})", new Object[] {String.format("%.2f", new Object[]{Float.valueOf((float)k / 1000.0F)}), String.format("%.2f", new Object[]{Float.valueOf(0.05F)})});
            LOGGER.fatal("Considering it to be crashed, server will forcibly shutdown.");
            ThreadMXBean threadmxbean = ManagementFactory.getThreadMXBean();
            ThreadInfo[] athreadinfo = threadmxbean.dumpAllThreads(true, true);
            StringBuilder stringbuilder = new StringBuilder();
            Error error = new Error();

            for (ThreadInfo threadinfo : athreadinfo)
            {
                if (threadinfo.getThreadId() == this.server.getServerThread().getId())
                {
                    error.setStackTrace(threadinfo.getStackTrace());
                }

                stringbuilder.append((Object)threadinfo);
                stringbuilder.append("\n");
            }

            CrashReport crashreport = new CrashReport("Watching Server", error);
            this.server.addServerInfoToCrashReport(crashreport);
            CrashReportCategory crashreportcategory = crashreport.makeCategory("Thread Dump");
            crashreportcategory.addCrashSection("Threads", stringbuilder);
            File file1 = new File(new File(this.server.getDataDirectory(), "crash-reports"), "crash-" + (new SimpleDateFormat("yyyy-MM-dd_HH.mm.ss")).format(new Date()) + "-server.txt");

            if (crashreport.saveToFile(file1))
            {
                LOGGER.error("This crash report has been saved to: {}", new Object[] {file1.getAbsolutePath()});
            }
            else
            {
                LOGGER.error("We were unable to save this crash report to disk.");
            }

            this.scheduleHalt();
        }

        this.firstRun = false;

        try
        {
            Thread.sleep(i + this.maxTickTime - j);
        }
        catch (InterruptedException var15)
        {
            ;
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:59,代码来源:ServerHangWatchdog.java


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