Package java.lang.management

Examples of java.lang.management.MemoryMXBean


       
        long threshold = max*3/4;
       
        threshold = Math.min( threshold, 5*1024*1024 );
       
        MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();

        NotificationEmitter emitter = (NotificationEmitter) mbean;

       
        emitter.addNotificationListener(
View Full Code Here


    * Access the max available RAM for this JVM.
    * You can increase it with 'java -Xmx256M ...'
    * @return bytes
    */
   public static long maxJvmMemory() {
       MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
       MemoryUsage usage = mbean.getHeapMemoryUsage() ;
       return usage.getMax();
   }
View Full Code Here

         String cname = oname.getCanonicalName();
         PlatformMBeanIDC mmidc = new PlatformMBeanIDC(server, oname, mbean);
         mbeans.put(cname, mmidc);
      }
      // MemoryMXBean
      MemoryMXBean mxbean = ManagementFactory.getMemoryMXBean();
      ObjectName mxname = new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME);
      PlatformMBeanIDC mxidc = new PlatformMBeanIDC(server, mxname, mxbean);
      mbeans.put(mxname.getCanonicalName(), mxidc);
     
      // MemoryPoolMXBeans
View Full Code Here

  {
    if (config.getBoolean("wrapper.java.monitor.heap", false))
    {
      final long cycle = config.getLong("wrapper.java.monitor.heap.interval", 30) * 1000;
      final int thresholdPercent = config.getInt("wrapper.java.monitor.heap.threshold.percent", 95);
      final MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
      final long maxHeap = bean.getHeapMemoryUsage().getMax();
      System.err.println("monitor heap: start");
      executor.execute(new Runnable()
      {

        public void run()
        {
          while (!_stopping)
          {
            float currentPercent = ((float) bean.getHeapMemoryUsage().getUsed() / maxHeap) * 100;
            if (currentPercent > thresholdPercent)
            {
              if (!_heapNotified)
              {
                System.err.println("wrapper.java.monitor.heap: HEAP SIZE EXCEEDS THRESHOLD: " + bean.getHeapMemoryUsage().getUsed()
                    + "/" + maxHeap);
                _heapNotified = true;
              }
            }
            else if (_heapNotified)
            {
              System.err.println("wrapper.java.monitor.heap: HEAP SIZE OK: " + bean.getHeapMemoryUsage().getUsed() + "/" + maxHeap);
              _heapNotified = false;

            }
            try
            {
View Full Code Here

                 System.err.println("Unable to classify GarbageCollectorMXBean [" + gcBean.getName() + "]");
             }
         }
      final GarbageCollectorMXBean minorGCBean = minorGCBeanX;
      final GarbageCollectorMXBean fullGCBean = fullGCBeanX;
      final MemoryMXBean bean = ManagementFactory.getMemoryMXBean();

      System.err.println("monitor gc: start");
      executor.execute(new Runnable()
      {
        private long lastMinorCollectionCount;
        private long lastMinorCollectionTime;

        private long lastFullCollectionCount;
        private long lastFullCollectionTime;
       
        Long usedHeap = null;
        Long timeMinorGC = null;
        Long timeFullGC = null;

        public void run()
        {
          if (minorGCBean == null)
          {
            System.err.println("monitor gc: could not find minorGCBean -> abort monitor");
            return;
          }
          if (fullGCBean == null)
          {
            System.err.println("monitor gc: could not find fullGCBean -> abort monitor");
            return;
          }
          try
          {
            while (!_stopping)
          {
            if (minorGCBean.getCollectionCount() != lastMinorCollectionCount) {
                       long diffCount = minorGCBean.getCollectionCount() - lastMinorCollectionCount;
                       long diffTime = minorGCBean.getCollectionTime() - lastMinorCollectionTime;
                       if (diffCount!= 0 && diffCount != 1)
                         timeMinorGC = diffTime/diffCount;
                       else
                         timeMinorGC = diffTime;
                       usedHeap = bean.getHeapMemoryUsage().getUsed();
                 
                       lastMinorCollectionCount = minorGCBean.getCollectionCount();
                       lastMinorCollectionTime = minorGCBean.getCollectionTime();
                   }
             
                   if (fullGCBean.getCollectionCount() != lastFullCollectionCount) {
                       long diffCount = fullGCBean.getCollectionCount() - lastFullCollectionCount;
                       long diffTime = fullGCBean.getCollectionTime() - lastFullCollectionTime;
                       if (diffCount!= 0 && diffCount != 1)
                         timeFullGC = diffTime/diffCount;
                       else
                         timeFullGC = diffTime;
                       usedHeap = bean.getHeapMemoryUsage().getUsed();
                 
                       lastFullCollectionCount = fullGCBean.getCollectionCount();
                       lastFullCollectionTime = fullGCBean.getCollectionTime();
                   }
                   if (usedHeap != null)
View Full Code Here

   * @param iThreshold
   */
  public OMemoryWatchDog(final float iThreshold) {
    OMemoryWatchDog.setPercentageUsageThreshold(iThreshold);

    final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();

    final NotificationEmitter memEmitter = (NotificationEmitter) memBean;
    memEmitter.addNotificationListener(new NotificationListener() {
      public synchronized void handleNotification(Notification n, Object hb) {
        if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
View Full Code Here

        report.setOs(str);
    }

    private void logMemoryInfo(Report report) {
        MemoryMXBean bean = ManagementFactory.getMemoryMXBean();
        report.setHeapMemoryUsage(bean.getHeapMemoryUsage().toString());
        report.setNonHeapMemoryUsage(bean.getNonHeapMemoryUsage().toString());
    }
View Full Code Here

  }

  private static long getMaxMemory()
  {
    try {
      MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
      MemoryUsage heap = memoryBean.getHeapMemoryUsage();

      if (heap.getCommitted() < heap.getMax())
        return heap.getMax();
      else
        return heap.getCommitted();
View Full Code Here

        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()));
        printValue("Pending objects", maxNameLen, Integer.toString(mem.getObjectPendingFinalizationCount()));
        for (GarbageCollectorMXBean gc : ManagementFactory.getGarbageCollectorMXBeans()) {
            String val = "Name = '" + gc.getName() + "', Collections = " + gc.getCollectionCount() + ", Time = " + printDuration(gc.getCollectionTime());
            printValue("Garbage collector", maxNameLen, val);
        }
View Full Code Here

        // Note that this is a very rough estimate and is not 100% reliable due
        // the various state of the VM's GC cycle.  Moreover, there appears to
        // be some constant overhead for each format type (i.e. structures for
        // the data itself) that isn't taken into account but should be.
        // Nevertheless, this still provides a best-effort attempt.
        MemoryMXBean m = ManagementFactory.getMemoryMXBean();
        MemoryUsage mu = m.getHeapMemoryUsage();
        long available = mu.getMax() - mu.getUsed();
        boolean inMemory = false;

        switch (format) {           
        // For binary formatted matrices, we assume that their size on disk
View Full Code Here

TOP

Related Classes of java.lang.management.MemoryMXBean

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.