Package java.lang.management

Examples of java.lang.management.ThreadMXBean


    private static final String DEADLOCK = "Found {0} {0,choice,1#deadlock|1<deadlocks}.";

    public void printThreads(ThreadWriter threadWriter)
    {
        final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();

        // thread Infos
        final ThreadInfo[] infos = getThreadInfo(threadMXBean);

        // map thread ids to infos idx
View Full Code Here


    start = now;
    return diff;
  }
 
  public static long getCpuTime( ) {
      ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
      return bean.isCurrentThreadCpuTimeSupported( ) ?
          bean.getCurrentThreadCpuTime( ) : 0L;
  }
View Full Code Here

          bean.getCurrentThreadCpuTime( ) : 0L;
  }
  
  /** Get user time in nanoseconds. */
  public static long getUserTime( ) {
      ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
      return bean.isCurrentThreadCpuTimeSupported( ) ?
          bean.getCurrentThreadUserTime( ) : 0L;
  }
View Full Code Here

          bean.getCurrentThreadUserTime( ) : 0L;
  }

  /** Get system time in nanoseconds. */
  public static long getSystemTime( ) {
      ThreadMXBean bean = ManagementFactory.getThreadMXBean( );
      return bean.isCurrentThreadCpuTimeSupported( ) ?
          (bean.getCurrentThreadCpuTime( ) - bean.getCurrentThreadUserTime( )) : 0L;
  }
View Full Code Here

        return running;
    }

    private String dumpThreads()
    {
        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() );
View Full Code Here

{

    @IgnoreJRERequirement
    public String call() throws Exception
    {
        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() );
View Full Code Here

   *
   * @return
   */
  public long getTimeInMillis()
    {
        ThreadMXBean bean = ManagementFactory.getThreadMXBean();
        return bean.isThreadCpuTimeEnabled() ?
            bean.getThreadCpuTime(threadId)/1000000 : System.currentTimeMillis();
    }
View Full Code Here

    // ---------- socket support

    private void dumpThreads(final Socket socket) throws IOException {

        final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
        final ThreadInfo[] threadInfos = threadBean.dumpAllThreads(true, true);

        for (ThreadInfo thread : threadInfos) {
            printThread(socket, thread);

            // add locked synchronizers
            final LockInfo[] locks = thread.getLockedSynchronizers();
            writeLine(socket, "-");
            writeLine(socket, "-   Locked ownable synchronizers:");
            if (locks.length > 0) {
                for (LockInfo li : locks) {
                    writeLine(socket, String.format("-        - locked %s",
                        formatLockInfo(
                            li.getClassName(),
                            li.getIdentityHashCode()
                        )
                    ));
                }
            } else {
                writeLine(socket, "-        - None");
            }

            // empty separator line
            writeLine(socket, "-");
        }

        final long[] deadLocked;
        if (threadBean.isSynchronizerUsageSupported()) {
            deadLocked = threadBean.findDeadlockedThreads();
        } else {
            deadLocked = threadBean.findMonitorDeadlockedThreads();
        }
        if (deadLocked != null) {
            final ThreadInfo[] dl = threadBean.getThreadInfo(deadLocked, true, true);
            final Set<ThreadInfo> dlSet = new HashSet<ThreadInfo>(Arrays.asList(dl));
            int deadlockCount = 0;
            for (ThreadInfo current : dl) {
                if (dlSet.remove(current)) {
View Full Code Here

     
      return new ETuple2(ERT.box(current_reds),ERT.box(since_last));     

    } else if (spec == am_runtime) {
     
      ThreadMXBean b = ManagementFactory.getThreadMXBean();
      long[] ts = b.getAllThreadIds();
      long current_runtime = 0;
      for (int i = 0; i < ts.length; i++) {
        long thread_time = b.getThreadCpuTime(ts[i]);
        if (thread_time != -1) { // it died in the mean time...
          current_runtime += thread_time;
        }
      }
      long since_last = (current_runtime - last_runtime) / 1000000;
View Full Code Here

    // can do a lot more here
    //JVM may support monitoring of object monitor usage and ownable synchronizer usage.
    //The getThreadInfo and dumpAllThreads methods can be used to obtain the thread stack
    //trace and synchronization information including which lock a thread is blocked to
    //acquire or waiting on and which locks the thread currently owns.
    ThreadMXBean tb = ManagementFactory.getThreadMXBean();
    System.out.println(tb.getThreadCount());
    System.out.println(tb.getPeakThreadCount())
   
   
   
       List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
      // One bean is returned for each memory pool provided, so we get the list of pools
View Full Code Here

TOP

Related Classes of java.lang.management.ThreadMXBean

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.