Package java.lang.management

Examples of java.lang.management.ThreadMXBean


    @Option(name = "-f", aliases = { "--file" }, description = "Write the thread information to the specified file")
    String file = null;
   
    protected Object doExecute() throws Exception {

        ThreadMXBean mxbean = ManagementFactory.getThreadMXBean();
        long[] threadIds = mxbean.findDeadlockedThreads();
        if (threadIds == null || threadIds.length == 0) {
            System.out.println("No deadlocked threads detected.");
        } else {
            ThreadInfo[] threads = mxbean.getThreadInfo(threadIds, true, true);
           
            File dumpFile = null;
            PrintWriter writer = null;
            if (file != null) {
                dumpFile = new File(file);
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("Pid", maxNameLen, getPid());
        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

  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

                    if (!isTestSuccess.get()) {
                        LOG.error("Test case has exceeded the maximum allotted time to run of: " + getMaxTestTime() + " ms.");
                        LOG.fatal("Test case has exceeded the maximum allotted time to run of: " + getMaxTestTime() + " ms.");
                       
                        if (LOG.isDebugEnabled()) {
                            ThreadMXBean threads = ManagementFactory.getThreadMXBean();
                            ThreadInfo[]  threadInfos = threads.getThreadInfo(threads.getAllThreadIds(), 50);
   
                            for (ThreadInfo threadInfo : threadInfos) {
                                LOG.debug(threadInfo);
                            }
                        }
View Full Code Here

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    long before = System.currentTimeMillis();
    long threadCPUtime = 0;
    String sessionString = "";
    ThreadMXBean cpuBean = ManagementFactory.getThreadMXBean();
    if (cpuBean.isCurrentThreadCpuTimeSupported()) {
      threadCPUtime = cpuBean.getCurrentThreadCpuTime();
    }
    if (request instanceof HttpServletRequest) {
      HttpServletRequest httpRequest = (HttpServletRequest) request;
      HttpSession session = httpRequest.getSession();
      SessionCounters counters;
      synchronized (requestsPerSession) {
        counters = (SessionCounters) requestsPerSession.get(session);
        if (counters == null) {
          counters = new SessionCounters();
          requestsPerSession.put(session, counters);
          logger.info("Starting new session #" + counters.sessionNumber + " for " + request.getRemoteHost() + " (" + request.getRemoteAddr() + ")");
          logRequestHeaders(httpRequest);
        }
        counters.requestCount++;
      }
      sessionString = "session #" + counters.sessionNumber + ", request #" + counters.requestCount + ": ";
      String query = "";
      if (httpRequest.getQueryString() != null) {
        query = "?" + httpRequest.getQueryString();
      }
      logger.info(sessionString + httpRequest.getMethod() + " " + httpRequest.getRequestURI() + query);
    } else {
      logger.info("Serving non-http request");
    }
    chain.doFilter(request, response);
    long after = System.currentTimeMillis();
    if (cpuBean.isCurrentThreadCpuTimeSupported()) {
      threadCPUtime = cpuBean.getCurrentThreadCpuTime() - threadCPUtime;
      logger.debug(sessionString + "Finished after " + (after - before) + "ms, " + (threadCPUtime / 1000000) + "ms cpu time used");
    } else {
      logger.debug(sessionString + "Finished after " + (after - before) + "ms");
    }
  }
View Full Code Here

    System.exit(0);
  }

  public static void printThreadInfo(PrintWriter stream, String title) {
    ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    final int STACK_DEPTH = 60;
    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()) + ":");
View Full Code Here

   * Returns CPU Time with nanosecond precision (not nanosecond accuracy). If the OS/JVM does not
   * support reporting the CPU Time, returns the wall clock time.
   */
  public synchronized long getCpuTime() {
    if (ManagementFactory.getPlatformMBeanServer() != null) {
      ThreadMXBean bean = ManagementFactory.getThreadMXBean();
      return bean.isCurrentThreadCpuTimeSupported() ? bean.getCurrentThreadCpuTime() : System
              .nanoTime();
    }
    return System.nanoTime();
  }
View Full Code Here

    return System.nanoTime();
  }

  private synchronized long getCpuTime(long threadId) {
    if (ManagementFactory.getPlatformMBeanServer() != null) {
      ThreadMXBean bean = ManagementFactory.getThreadMXBean();
      return bean.isCurrentThreadCpuTimeSupported() ? bean.getThreadCpuTime(threadId) : System
              .nanoTime();
    }
    return System.nanoTime();
  }
View Full Code Here

    }
   
    if (this.connection.getIncludeThreadDumpInDeadlockExceptions()) {
      errorBuf.append("\n\n*** Java threads running at time of deadlock ***\n\n");
     
      ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean();
      long[] threadIds = threadMBean.getAllThreadIds();

      ThreadInfo[] threads = threadMBean.getThreadInfo(threadIds,
          Integer.MAX_VALUE);
      List<ThreadInfo> activeThreads = new ArrayList<ThreadInfo>();

      for (ThreadInfo info : threads) {
        if (info != null) {
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.