Package java.lang.management

Examples of java.lang.management.ThreadMXBean


   private static String INDENT = "    ";

   public static String threadDump() {
      StringBuilder threadDump = new StringBuilder();
      ThreadMXBean threadMx = ManagementFactory.getThreadMXBean();
      if (threadMx.isObjectMonitorUsageSupported() && threadMx.isSynchronizerUsageSupported()) {
         // Print lock info if, and only if, both object monitor usage and synchronizer usage are supported.
          dumpThreadInfo(threadDump, true, threadMx);
      } else {
         dumpThreadInfo(threadDump, false, threadMx);
      }
View Full Code Here


      ObjectName rtname = new ObjectName(ManagementFactory.RUNTIME_MXBEAN_NAME);
      PlatformMBeanIDC rtidc = new PlatformMBeanIDC(server, rtname, rtbean);
      mbeans.put(rtname.getCanonicalName(), rtidc);

      // ThreadMXBean
      ThreadMXBean tbean = ManagementFactory.getThreadMXBean();
      ObjectName tname = new ObjectName(ManagementFactory.THREAD_MXBEAN_NAME);
      PlatformMBeanIDC tidc = new PlatformMBeanIDC(server, tname, tbean);
      mbeans.put(tname.getCanonicalName(), tidc);
   }
View Full Code Here

   private static String INDENT = "    ";

   public static String threadDump() {
      StringBuilder threadDump = new StringBuilder();
      ThreadMXBean threadMx = ManagementFactory.getThreadMXBean();
      if (threadMx.isObjectMonitorUsageSupported() && threadMx.isSynchronizerUsageSupported()) {
         // Print lock info if, and only if, both object monitor usage and synchronizer usage are supported.
          dumpThreadInfo(threadDump, true, threadMx);
      } else {
         dumpThreadInfo(threadDump, false, threadMx);
      }
View Full Code Here

    }


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

    protected Object doExecute() throws Exception {
        int maxNameLen;

        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
        ThreadMXBean threads = ManagementFactory.getThreadMXBean();
        MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
        ClassLoadingMXBean cl = ManagementFactory.getClassLoadingMXBean();

        //
        // print Karaf informations
        //
        maxNameLen = 25;
        System.out.println("Karaf");
        printValue("Karaf version", maxNameLen, System.getProperty("karaf.version"));
        printValue("Karaf home", maxNameLen, System.getProperty("karaf.home"));
        printValue("Karaf base", maxNameLen, System.getProperty("karaf.base"));
        printValue("OSGi Framework", maxNameLen, bundleContext.getBundle(0).getSymbolicName() + " - " +
                bundleContext.getBundle(0).getVersion());
        System.out.println();

        System.out.println("JVM");
        printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
        printValue("Version", maxNameLen, System.getProperty("java.version"));
        printValue("Vendor", maxNameLen, runtime.getVmVendor());
        printValue("Uptime", maxNameLen, printDuration(runtime.getUptime()));
        try {
            printValue("Process CPU time", maxNameLen, printDuration(getSunOsValueAsLong(os, "getProcessCpuTime") / 1000000));
        } catch (Throwable t) {
        }
        printValue("Total compile time", maxNameLen, printDuration(ManagementFactory.getCompilationMXBean().getTotalCompilationTime()));

        System.out.println("Threads");
        printValue("Live threads", maxNameLen, Integer.toString(threads.getThreadCount()));
        printValue("Daemon threads", maxNameLen, Integer.toString(threads.getDaemonThreadCount()));
        printValue("Peak", maxNameLen, Integer.toString(threads.getPeakThreadCount()));
        printValue("Total started", maxNameLen, Long.toString(threads.getTotalStartedThreadCount()));

        System.out.println("Memory");
        printValue("Current heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getUsed()));
        printValue("Maximum heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getMax()));
        printValue("Committed heap size", maxNameLen, printSizeInKb(mem.getHeapMemoryUsage().getCommitted()));
View Full Code Here

            case 't': {
                try {
                    // TODO: Once we drop support for Java 5, we can use ThreadMXBean.dumpAllThreads(false, false)
                    //       (introduced in Java 6) here instead.
                    ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
                    long[] allIds = threadMXBean.getAllThreadIds();
                    ThreadInfo[] allInfo = threadMXBean.getThreadInfo(allIds, 256);
                    for (ThreadInfo threadInfo : allInfo) {
                        if (threadInfo != null) {
                            out.println(threadInfo);
                        }
                    }
View Full Code Here

public class ThreadDataMeasurementComponent extends MBeanResourceComponent {
    @Override
    public OperationResult invokeOperation(String name, Configuration parameters) throws InterruptedException,
        Exception {
        if ("threadDump".equals(name)) {
            ThreadMXBean threadBean = getEmsBean().getProxy(ThreadMXBean.class);

            long[] threadIds = threadBean.getAllThreadIds();
            ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadIds, Integer.MAX_VALUE);
            OperationResult result = new OperationResult();
            Configuration resultConfig = result.getComplexResults();
            resultConfig.put(new PropertySimple("totalCount", threadBean.getThreadCount()));
            PropertyList threadList = new PropertyList("threadList");
            resultConfig.put(threadList);
            for (ThreadInfo threadInfo : threadInfos) {
                PropertyMap map = new PropertyMap("thread");
                map.put(new PropertySimple("name", threadInfo.getThreadName()));
View Full Code Here

        }
    }

    private Double getSuspendedThreadsCount(EmsBean bean) {
        Double res = 0.0;
        ThreadMXBean threadBean = bean.getProxy(ThreadMXBean.class);
        long[] tids = threadBean.getAllThreadIds();
        ThreadInfo[] tinfos = threadBean.getThreadInfo(tids, Integer.MAX_VALUE);
        for (ThreadInfo ti : tinfos) {
            if ((ti != null) && (ti.isSuspended()))
                res++;
        }
        return res;
View Full Code Here

        }
        return res;
    }

    private Double getDeadLockedThreadsCount(EmsBean bean) {
        ThreadMXBean threadBean = bean.getProxy(ThreadMXBean.class);
        long[] tids = threadBean.findMonitorDeadlockedThreads();
        if (tids == null) {
            return 0.0;
        } else {
            return new Double(tids.length);
        }
View Full Code Here

  public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws IOException
  {   
    SimpleOrderedMap<Object> system = new SimpleOrderedMap<Object>();
    rsp.add( "system", system );

    ThreadMXBean tmbean = ManagementFactory.getThreadMXBean();
   
    // Thread Count
    SimpleOrderedMap<Object> nl = new SimpleOrderedMap<Object>();
    nl.add( "current",tmbean.getThreadCount() );
    nl.add( "peak", tmbean.getPeakThreadCount() );
    nl.add( "daemon", tmbean.getDaemonThreadCount() );
    system.add( "threadCount", nl );
   
    // Deadlocks
    ThreadInfo[] tinfos;
    long[] tids = tmbean.findMonitorDeadlockedThreads();
    if (tids != null) {
      tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
      NamedList<SimpleOrderedMap<Object>> lst = new NamedList<SimpleOrderedMap<Object>>();
      for (ThreadInfo ti : tinfos) {
        lst.add( "thread", getThreadInfo( ti, tmbean ) );
      }
      system.add( "deadlocks", lst );
    }
   
    // Now show all the threads....
    tids = tmbean.getAllThreadIds();
    tinfos = tmbean.getThreadInfo(tids, Integer.MAX_VALUE);
    NamedList<SimpleOrderedMap<Object>> lst = new NamedList<SimpleOrderedMap<Object>>();
    for (ThreadInfo ti : tinfos) {
      lst.add( "thread", getThreadInfo( ti, tmbean ) );
    }
    system.add( "threadDump", lst );
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.