Package java.lang.management

Examples of java.lang.management.ThreadInfo


        StringBuilder sb=new StringBuilder();
        ThreadMXBean bean=ManagementFactory.getThreadMXBean();
        long[] ids=bean.getAllThreadIds();
        ThreadInfo[] threads=bean.getThreadInfo(ids, 20);
        for(int i=0; i < threads.length; i++) {
            ThreadInfo info=threads[i];
            if(info == null)
                continue;
            sb.append(info.getThreadName()).append(":\n");
            StackTraceElement[] stack_trace=info.getStackTrace();
            for(int j=0; j < stack_trace.length; j++) {
                StackTraceElement el=stack_trace[j];
                sb.append("    at ").append(el.getClassName()).append(".").append(el.getMethodName());
                sb.append("(").append(el.getFileName()).append(":").append(el.getLineNumber()).append(")");
                sb.append("\n");
View Full Code Here


        }
       
        new_times.put( id, time );
      }
     
      ThreadInfo  info = bean.getThreadInfo( ids[biggest_index ]);

      String  thread_name = info==null?"<dead>":info.getThreadName();
     
      int  percent = (int)( 100*biggest_diff / time_available );
     
      Runtime rt = Runtime.getRuntime();
     
      log.log( "Thread state: elapsed=" + elapsed + ",cpu=" + total_diffs + ",max=" + thread_name + "(" + biggest_diff + "/" + percent + "%),mem:max=" + (rt.maxMemory()/1024)+",tot=" + (rt.totalMemory()/1024) +",free=" + (rt.freeMemory()/1024));
     
      if ( biggest_diff > time_available/4 ){
       
        info = bean.getThreadInfo( ids[biggest_index ], 255 );
       
        if ( info == null ){
         
          log.log( "    no info for max thread" );
         
        }else{
         
          StackTraceElement[] elts = info.getStackTrace();
          StringBuilder str = new StringBuilder(elts.length * 20);
         
          str.append("    ");
          for (int i=0;i<elts.length;i++){
            if(i != 0)
View Full Code Here

    writer.println("Threads " + allThreadIds.length);
    writer.indent();

    List<ThreadInfo> threadInfos = new ArrayList<ThreadInfo>(allThreadIds.length);
    for (int i = 0; i < allThreadIds.length; i++) {
      ThreadInfo info = threadBean.getThreadInfo(allThreadIds[i], 32);
      if(info != null)
        threadInfos.add(info);
    }

    if (!disable_getThreadCpuTime) {
      Collections.sort(threadInfos, new Comparator<ThreadInfo>() {
        public int compare(ThreadInfo o1, ThreadInfo o2) {
         
          long diff = threadBean.getThreadCpuTime(o2.getThreadId())
              - threadBean.getThreadCpuTime(o1.getThreadId());
          if (diff == 0) {
            return o1.getThreadName().compareToIgnoreCase(o2.getThreadName());
          }
          return diff > 0 ? 1 : -1;
        }
      });
    }

    for (int i = 0; i < threadInfos.size(); i++) {
      try {
        ThreadInfo threadInfo = threadInfos.get(i);

        long lCpuTime = disable_getThreadCpuTime ? -1
            : threadBean.getThreadCpuTime(threadInfo.getThreadId());
        if (lCpuTime == 0)
          break;

        String sState;
        switch (threadInfo.getThreadState()) {
          case BLOCKED:
            sState = "Blocked";
            break;
          case RUNNABLE:
            sState = "Runnable";
            break;
          case NEW:
            sState = "New";
            break;
          case TERMINATED:
            sState = "Terminated";
            break;
          case TIMED_WAITING:
            sState = "Timed Waiting";
            break;

          case WAITING:
            sState = "Waiting";
            break;

          default:
            sState = "" + threadInfo.getThreadState();
            break;

        }

        String sName = threadInfo.getThreadName();
        String sLockName = threadInfo.getLockName();

        writer.println(sName
            + ": "
            + sState
            + ", "
            + (lCpuTime / 1000000)
            + "ms CPU, "
            + "B/W: "
            + threadInfo.getBlockedCount()
            + "/"
            + threadInfo.getWaitedCount()
            + (sLockName == null ? "" : "; Locked by " + sLockName + "/"
                + threadInfo.getLockOwnerName()));

        writer.indent();
        try {
          StackTraceElement[] stackTrace = threadInfo.getStackTrace();
          for (int j = 0; j < stackTrace.length; j++) {
            writer.println(stackTrace[j].toString());
          }
        } finally {
          writer.exdent();
View Full Code Here

      MetaValue tid0InfoMV = getThreadInfo.invoke(tid0SV);
      assertNotNull(tid0InfoMV);
      assertTrue(tid0InfoMV instanceof CompositeValue);
      log.debug(tid0InfoMV);
      CompositeValue tid0InfoCV = (CompositeValue) tid0InfoMV;
      ThreadInfo tid0Info = ManagementFactoryUtils.unwrapThreadInfo(tid0InfoCV);
      log.debug(tid0Info);
   }
View Full Code Here

      long[] threads = threadMXBean.getAllThreadIds();
      for (int i = 0; i < threads.length; ++i)
      {
         Long id = new Long(threads[i]);
         Long cpuTime = threadMXBean.getThreadCpuTime(id);
         ThreadInfo threadInfo = threadMXBean.getThreadInfo(id, ZERO );
         if (threadInfo != null)
         {
            String name = threadInfo.getThreadName();
            result.add(new ThreadCPU(name, cpuTime.longValue()));
         }
      }
      return result;
   }
View Full Code Here

   {
      // Get the threadId
      Long threadId = thread.getId();

      // Get the ThreadInfo object for that threadId, max StackTraceElement depth
      ThreadInfo threadInfo = threadMXBean.getThreadInfo(threadId, new Integer(Integer.MAX_VALUE));
     
      outputJdk5ThreadMXBeanInfo(sbuf, threadInfo);     
   }
View Full Code Here

                    deadlocks.add(idxs);

                    do
                    {
                        idxs.add(idx);
                        ThreadInfo info = infos[idx.intValue()];
                        if (info != null)
                        {
                            idx = (Integer) id2idx.remove(Long.valueOf(info.getLockOwnerId()));
                        }
                        else
                        {
                            idx = null;
                        }
                    }
                    while (idx != null);
                }
            }

            for (Iterator di = deadlocks.iterator(); di.hasNext();)
            {
                List idxs = (List) di.next();

                threadWriter.printEmptyLine();
                threadWriter.println("Found one Java-level deadlock:");
                threadWriter.println("=============================");

                for (Iterator ii = idxs.iterator(); ii.hasNext();)
                {
                    Integer idx = (Integer) ii.next();
                    ThreadInfo info = infos[idx.intValue()];

                    printDeadlockedThreadInfo(threadWriter, info);
                }

                threadWriter.printEmptyLine();
View Full Code Here

        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        StringBuffer b = new StringBuffer( "Thread dump\n" );
        ThreadInfo[] infos = threadMXBean.dumpAllThreads( threadMXBean.isObjectMonitorUsageSupported(), threadMXBean.isSynchronizerUsageSupported() );
        for ( int i = 0; i < infos.length; i++ )
        {
            ThreadInfo ti = infos[i];
            b.append( "\n\nThreadId: " ).append( ti.getThreadId() ).append( " : name: " ).append( ti.getThreadName() ).append( " State: " ).append( ti.getThreadState() );
            b.append( "\n  LockInfo: " ).append( ti.getLockInfo() ).append( " LockOwnerId: " ).append( ti.getLockOwnerId() ).append( " LockOwnerName: ").append( ti.getLockOwnerName() );
            StackTraceElement[] stackTrace = ti.getStackTrace();
            for (int j = 0; j < stackTrace.length; j++ )
            {
                b.append( "\n  " ).append( stackTrace[j] );
            }
        }
View Full Code Here

        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        StringBuffer b = new StringBuffer( "Thread dump\n" );
        ThreadInfo[] infos = threadMXBean.dumpAllThreads( threadMXBean.isObjectMonitorUsageSupported(), threadMXBean.isSynchronizerUsageSupported() );
        for ( int i = 0; i < infos.length; i++ )
        {
            ThreadInfo ti = infos[i];
            b.append( "\n\nThreadId: " ).append( ti.getThreadId() ).append( " : name: " ).append( ti.getThreadName() ).append( " State: " ).append( ti.getThreadState() );
            b.append( "\n  LockInfo: " ).append( ti.getLockInfo() ).append( " LockOwnerId: " ).append( ti.getLockOwnerId() ).append( " LockOwnerName: ").append( ti.getLockOwnerName() );
            StackTraceElement[] stackTrace = ti.getStackTrace();
            for (int j = 0; j < stackTrace.length; j++ )
            {
                b.append( "\n  " ).append( stackTrace[j] );
            }
        }
View Full Code Here

      ThreadMXBean bean = ManagementFactory.getThreadMXBean();
      long[] ids = bean.getAllThreadIds();
      ThreadInfo[] threads = bean.getThreadInfo(ids, 20);
      for (int i = 0; i < threads.length; i++)
      {
         ThreadInfo info = threads[i];
         if (info == null)
            continue;
         sb.append(info.getThreadName()).append(":\n");
         StackTraceElement[] stack_trace = info.getStackTrace();
         for (int j = 0; j < stack_trace.length; j++)
         {
            StackTraceElement el = stack_trace[j];
            sb.append("at ").append(el.getClassName()).append(".").append(el.getMethodName());
            sb.append("(").append(el.getFileName()).append(":").append(el.getLineNumber()).append(")");
View Full Code Here

TOP

Related Classes of java.lang.management.ThreadInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.