Package java.lang.management

Examples of java.lang.management.ThreadMXBean


      throw new Exception("Class attribute is not nominal!");
    }
    if (m_Template == null) {
      throw new Exception("No classifier has been specified");
    }
    ThreadMXBean thMonitor = ManagementFactory.getThreadMXBean();
    boolean canMeasureCPUTime = thMonitor.isThreadCpuTimeSupported();
    if(!thMonitor.isThreadCpuTimeEnabled())
      thMonitor.setThreadCpuTimeEnabled(true);
   
    int addm = (m_AdditionalMeasures != null) ? m_AdditionalMeasures.length : 0;
    Object [] result = new Object[RESULT_SIZE+addm];
    long thID = Thread.currentThread().getId();
    long CPUStartTime=-1, trainCPUTimeElapsed=-1, testCPUTimeElapsed=-1,
         trainTimeStart, trainTimeElapsed, testTimeStart, testTimeElapsed;   
   
    String costName = train.relationName() + CostMatrix.FILE_EXTENSION;
    File costFile = new File(getOnDemandDirectory(), costName);
    if (!costFile.exists()) {
      throw new Exception("On-demand cost file doesn't exist: " + costFile);
    }
    CostMatrix costMatrix = new CostMatrix(new BufferedReader(
    new FileReader(costFile)));
   
    Evaluation eval = new Evaluation(train, costMatrix);   
    m_Classifier = AbstractClassifier.makeCopy(m_Template);
   
    trainTimeStart = System.currentTimeMillis();
    if(canMeasureCPUTime)
      CPUStartTime = thMonitor.getThreadUserTime(thID);
    m_Classifier.buildClassifier(train);
    if(canMeasureCPUTime)
      trainCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;
    trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
    testTimeStart = System.currentTimeMillis();
    if(canMeasureCPUTime)
      CPUStartTime = thMonitor.getThreadUserTime(thID);
    eval.evaluateModel(m_Classifier, test);
    if(canMeasureCPUTime)
      testCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;
    testTimeElapsed = System.currentTimeMillis() - testTimeStart;
    thMonitor = null;
   
    m_result = eval.toSummaryString();
    // The results stored are all per instance -- can be multiplied by the
View Full Code Here


    overall_length += NUM_WEIGHTED_IR_STATISTICS;
    overall_length += NUM_UNWEIGHTED_IR_STATISTICS;
    if (getAttributeID() >= 0) overall_length += 1;
    if (getPredTargetColumn()) overall_length += 2;
   
    ThreadMXBean thMonitor = ManagementFactory.getThreadMXBean();
    boolean canMeasureCPUTime = thMonitor.isThreadCpuTimeSupported();
    if(!thMonitor.isThreadCpuTimeEnabled())
      thMonitor.setThreadCpuTimeEnabled(true);
   
    Object [] result = new Object[overall_length];
    Evaluation eval = new Evaluation(train);
    m_Classifier = AbstractClassifier.makeCopy(m_Template);
    double [] predictions;
    long thID = Thread.currentThread().getId();
    long CPUStartTime=-1, trainCPUTimeElapsed=-1, testCPUTimeElapsed=-1,
         trainTimeStart, trainTimeElapsed, testTimeStart, testTimeElapsed;   

    //training classifier
    trainTimeStart = System.currentTimeMillis();
    if(canMeasureCPUTime)
      CPUStartTime = thMonitor.getThreadUserTime(thID);
    m_Classifier.buildClassifier(train);   
    if(canMeasureCPUTime)
      trainCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;
    trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
   
    //testing classifier
    testTimeStart = System.currentTimeMillis();
    if(canMeasureCPUTime)
      CPUStartTime = thMonitor.getThreadUserTime(thID);
    predictions = eval.evaluateModel(m_Classifier, test);
    if(canMeasureCPUTime)
      testCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;
    testTimeElapsed = System.currentTimeMillis() - testTimeStart;
    thMonitor = null;
   
    m_result = eval.toSummaryString();
    // The results stored are all per instance -- can be multiplied by the
View Full Code Here

      throw new Exception("Class attribute is not numeric!");
    }
    if (m_Template == null) {
      throw new Exception("No classifier has been specified");
    }
    ThreadMXBean thMonitor = ManagementFactory.getThreadMXBean();
    boolean canMeasureCPUTime = thMonitor.isThreadCpuTimeSupported();
    if(!thMonitor.isThreadCpuTimeEnabled())
      thMonitor.setThreadCpuTimeEnabled(true);
   
    int addm = (m_AdditionalMeasures != null) ? m_AdditionalMeasures.length : 0;
    Object [] result = new Object[RESULT_SIZE+addm];
    long thID = Thread.currentThread().getId();
    long CPUStartTime=-1, trainCPUTimeElapsed=-1, testCPUTimeElapsed=-1,
         trainTimeStart, trainTimeElapsed, testTimeStart, testTimeElapsed;   
    Evaluation eval = new Evaluation(train);
    m_Classifier = AbstractClassifier.makeCopy(m_Template);

    trainTimeStart = System.currentTimeMillis();
    if(canMeasureCPUTime)
      CPUStartTime = thMonitor.getThreadUserTime(thID);
    m_Classifier.buildClassifier(train);
    if(canMeasureCPUTime)
      trainCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;
    trainTimeElapsed = System.currentTimeMillis() - trainTimeStart;
    testTimeStart = System.currentTimeMillis();
    if(canMeasureCPUTime)
      CPUStartTime = thMonitor.getThreadUserTime(thID);
    eval.evaluateModel(m_Classifier, test);
    if(canMeasureCPUTime)
      testCPUTimeElapsed = thMonitor.getThreadUserTime(thID) - CPUStartTime;
    testTimeElapsed = System.currentTimeMillis() - testTimeStart;
    thMonitor = null;
   
    m_result = eval.toSummaryString();
    // The results stored are all per instance -- can be multiplied by the
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

    if ( num_processors < 1 ){
     
      num_processors = 1;
    }
   
    ThreadMXBean  bean = ManagementFactory.getThreadMXBean();
   
    log.log( "Monitoring starts (processors =" + num_processors + ")" );
   
    if ( !bean.isThreadCpuTimeSupported()){
     
      log.log( "ThreadCpuTime not supported" );
     
      return;
    }
   
    if ( !bean.isThreadCpuTimeEnabled()){
     
      log.log( "Enabling ThreadCpuTime" );
     
      bean.setThreadCpuTimeEnabled( true );
    }
   
    Map<Long,Long>  last_times = new HashMap<Long,Long>();
   
    long  time_available = 10000;
   
    while( true ){
     
      long  start = System.currentTimeMillis();
     
      try{
       
        Thread.sleep(time_available);
       
      }catch( Throwable e ){
       
        log.log(e);
      }
   
      long  end = System.currentTimeMillis();
     
      long  elapsed = end - start;
     
      long[]  ids   = bean.getAllThreadIds();
     
      long[]  diffs   = new long[ids.length];
     
      long  total_diffs   = 0;
      long  biggest_diff   = 0;
      int    biggest_index  = 0;
     
      Map<Long,Long>  new_times = new HashMap<Long,Long>();
     
      for (int i=0;i<ids.length;i++){
     
        long  id = ids[i];
       
        long  time = bean.getThreadCpuTime( id )/1000000// nanos -> millis
       
        Long  old_time = last_times.get( id );
       
        if ( old_time != null ){
         
          long  diff = time - old_time.longValue();
         
          if ( diff > biggest_diff ){
           
            biggest_diff  = diff;
           
            biggest_index  = i;
          }
         
          diffs[i] = diff;
         
          total_diffs += diff;
        }
       
        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" );
         
View Full Code Here

 
  private static void
  dumpThreads(
    IndentWriter    writer )
  {
    final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();

    long[] allThreadIds = threadBean.getAllThreadIds();
    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()) {
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 void monitorDeadLocks(YajswConfigurationImpl config)
  {
    if (config.getBoolean("wrapper.java.monitor.deadlock", false))
    {
      final long cycle = config.getLong("wrapper.java.monitor.deadlock.interval", 30) * 1000;
      final ThreadMXBean bean = ManagementFactory.getThreadMXBean();
      System.err.println("monitor deadlock: start");
      executor.execute(new Runnable()
      {

        public void run()
        {
          while (!_stopping)
          {
            long[] ids = bean.findDeadlockedThreads();
            if (ids != null && ids.length > 0)
            {
              System.err.println("wrapper.java.monitor.deadlock: DEADLOCK IN THREADS: ");
              threadDump(ids);
              // exit loop once we find a deadlock
View Full Code Here

public class ThreadDumpImpl6 implements Action
{
  public void execute(Message msg, Channel session, PrintStream out, Object data) throws IOException
  {
    final ThreadMXBean thbean = ManagementFactory.getThreadMXBean();
    final long[] ids = (long[]) (data == null ? thbean.getAllThreadIds() : data);
    Map threads = Thread.getAllStackTraces();
    Map<Long, Thread> threadIds = new HashMap();
    for (Iterator it = threads.keySet().iterator(); it.hasNext();)
    {
      Thread t = (Thread) it.next();
      threadIds.put(t.getId(), t);
    }

    synchronized (ids)
    {

      ThreadInfo[] infos;
      if (!thbean.isObjectMonitorUsageSupported() || !thbean.isSynchronizerUsageSupported())
        infos = thbean.getThreadInfo(ids);
      else
        infos = thbean.getThreadInfo(ids, true, true);

      for (ThreadInfo info : infos)
      {
        String locked = info.getLockOwnerName();
        String daemon = threadIds.get(info.getThreadId()).isDaemon() ? "DAEMON" : "";
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 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

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.