Package java.lang.management

Examples of java.lang.management.ThreadInfo



    protected static void _printThreads(ThreadMXBean bean, long[] ids, StringBuilder sb) {
        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


        long threadId = record.getThreadID();
        String threadName = "" + record.getThreadID();
        ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        for (long id : threadMXBean.getAllThreadIds()) {
            if (id == threadId) {
                ThreadInfo threadInfo = threadMXBean.getThreadInfo(id);
                if (threadInfo != null) {
                    threadName = threadInfo.getThreadName();
                }
                break;
            }
        }
View Full Code Here

            final long endTime = clock.time();

            final long roundBlockedTime;
            if (supportsThreadContention) {
                final long threadId = Thread.currentThread().getId();
                final ThreadInfo threadInfo = threadMXBean.getThreadInfo(threadId);
                final long threadBlockedTime = threadInfo.getBlockedTime();
                final long previousValue = previousThreadBlockedTime.get().getAndSet(threadBlockedTime);
                roundBlockedTime = threadBlockedTime - previousValue;
            } else {
                roundBlockedTime = 0;
            }
View Full Code Here

            if ( null != threads ) {
                StringBuffer sb = new StringBuffer( 256 );
                ThreadInfo[] infos = threadMXBean.getThreadInfo( threads, Integer.MAX_VALUE );

                for (int i = 0; i < infos.length; i ++) {
                    ThreadInfo info = infos[i];
                    sb.append( info.getThreadName() )
                        .append( " blocked on " )
                        .append( info.getLockName() )
                        .append( " owned by " )
                        .append( info.getLockOwnerName() )
                        .append( "\n" );
                }

                for (int i = 0; i < infos.length; i ++) {
                    ThreadInfo info = infos[i];
                    sb.append( "\nStack for " ).append( info.getThreadName() ).append( "\n" );
                    StackTraceElement[] stackTrace = info.getStackTrace();
                    for (int j = 0; j < stackTrace.length; j ++) {
                        sb.append( "\t" ).append( stackTrace[j] ).append( "\n" );
                    }
                }
View Full Code Here

    boolean contention = threadBean.isThreadContentionMonitoringEnabled();
    long[] threadIds = threadBean.getAllThreadIds();
    stream.println("Process Thread Dump: " + title);
    stream.println(threadIds.length + " active threads");
    for (long tid: threadIds) {
      ThreadInfo info = threadBean.getThreadInfo(tid, STACK_DEPTH);
      if (info == null) {
        stream.println("  Inactive");
        continue;
      }
      stream.println("Thread " +
                     getTaskName(info.getThreadId(),
                                 info.getThreadName()) + ":");
      Thread.State state = info.getThreadState();
      stream.println("  State: " + state);
      stream.println("  Blocked count: " + info.getBlockedCount());
      stream.println("  Waited count: " + info.getWaitedCount());
      if (contention) {
        stream.println("  Blocked time: " + info.getBlockedTime());
        stream.println("  Waited time: " + info.getWaitedTime());
      }
      if (state == Thread.State.WAITING) {
        stream.println("  Waiting on " + info.getLockName());
      } else  if (state == Thread.State.BLOCKED) {
        stream.println("  Blocked on " + info.getLockName());
        stream.println("  Blocked by " +
                       getTaskName(info.getLockOwnerId(),
                                   info.getLockOwnerName()));
      }
      stream.println("  Stack:");
      for (StackTraceElement frame: info.getStackTrace()) {
        stream.println("    " + frame.toString());
      }
    }
    stream.flush();
  }
View Full Code Here

        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

   public static ThreadInfo unwrapThreadInfo(CompositeValue mv)
      throws OpenDataException, ClassNotFoundException
   {
      CompositeData cd = (CompositeData) getOpenValue(mv);
      ThreadInfo ti = ThreadInfo.from(cd);
      return ti;
   }
View Full Code Here

        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

                SimpleType.STRING, stackTraceArray, SimpleType.STRING };
        CompositeType compositeType = getCompositeType(initialNames, types);
        CompositeData data = new CompositeDataSupport(compositeType,
                initialNames, initialValues);
        ThreadInfo.from(data);
        ThreadInfo threadInfo = ThreadInfo.from(data);
        assertEquals(initialValues[0], threadInfo.getThreadId());
        assertEquals(initialValues[1], threadInfo.getThreadName());
        assertEquals(GOOD_THREAD_STATE, threadInfo.getThreadState());
        assertEquals(initialValues[3], threadInfo.isSuspended());
        assertEquals(initialValues[4], threadInfo.isInNative());
        assertEquals(initialValues[5], threadInfo.getBlockedCount());
        assertEquals(initialValues[6], threadInfo.getBlockedTime());
        assertEquals(initialValues[7], threadInfo.getWaitedCount());
        assertEquals(initialValues[8], threadInfo.getWaitedTime());
        assertEquals(initialValues[9], threadInfo.getLockName());
        assertEquals(initialValues[10], threadInfo.getLockOwnerId());
        assertNull(threadInfo.getLockOwnerName());
        StackTraceElement[] stackElements = threadInfo.getStackTrace();
        assertEquals(GOOD_STACK_SIZE, stackElements.length);
        for (StackTraceElement element : stackElements) {
            assertEquals(GOOD_STACK_CLASSNAME, element.getClassName());
            assertEquals(GOOD_STACK_NATIVEMETHOD, element.isNativeMethod());
            assertEquals(GOOD_STACK_FILENAME, element.getFileName());
View Full Code Here

        long[] ids = mbean.getAllThreadIds();
        if (ids != null)
        {
            for (long id : ids)
            {
                ThreadInfo threadInfo = mbean.getThreadInfo(id, STACK_DUMP_SIZE_BLOCKED);
                buf.append("\n").append(threadInfo).append("\n");

                // Dump the monitor blocks
                String lockName = threadInfo.getLockName();
                if (lockName != null)
                {
                    buf.append("  waiting for ");
                    buf.append(lockName);
                    buf.append(" blocked by ");
                    buf.append(threadInfo.getLockOwnerName());
                    buf.append("@").append(threadInfo.getLockOwnerId()).append("\n");
                }

                // Write the stack trace of thread
                StackTraceElement[] traces = threadInfo.getStackTrace();
                int steps = requiresDetails(threadInfo)
                    ? traces.length : Math.min(STACK_DUMP_SIZE_NORMAL, traces.length);

                for (int j = 0; j < steps; j++)
                {
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.