Examples of MemoryPoolMXBean


Examples of java.lang.management.MemoryPoolMXBean

  initialise()
  {
    try{
      List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
   
      MemoryPoolMXBean   pool_to_monitor = null;
      long        ptm_size    = 0;
     
      long  overall_max = 0;
     
      for ( MemoryPoolMXBean pool: pools ){
     
        long pool_max = pool.getUsage().getMax();
       
        if ( pool_max > 0 ){
         
          if ( pool.getType() == MemoryType.HEAP ){
         
            overall_max += pool_max;
          }
        }
       
        if ( pool.getType() == MemoryType.HEAP && pool.isCollectionUsageThresholdSupported()){
       
          long max = pool.getUsage().getMax();
         
          if ( max > ptm_size ){
           
            pool_to_monitor = pool;
            ptm_size    = max;
          }
        }
      }
     
      max_heap_mb = (overall_max+MB-1)/MB;

      if ( pool_to_monitor != null ){

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

        NotificationEmitter emitter = (NotificationEmitter) mbean;

       
        emitter.addNotificationListener(
          new NotificationListener()
          {
            private long  last_mb_log = Long.MAX_VALUE;
           
            private boolean increase_tried;
           
            public void
            handleNotification(
              Notification   notification,
              Object       handback )
            {
              MemoryPoolMXBean pool = (MemoryPoolMXBean)handback;

              long used   = pool.getCollectionUsage().getUsed();
              long max   = pool.getUsage().getMax();
             
              long avail = max-used;
             
              if ( avail < 0 ){
                avail = 0;
              }
             
              long  mb = (avail+MB-1)/(MB);
             
              if ( mb <= 4 ){
               
                synchronized( this ){
                 
                  if ( mb >= last_mb_log ){
                   
                    return;
                  }
                 
                  last_mb_log = mb;
                }
               
                Runtime runtime = Runtime.getRuntime();
               
                Debug.out( "MemMon: notify triggered: pool=" + pool.getName() +
                      ", used=" + used +
                      ", max=" + max +
                      ": runtime free=" + runtime.freeMemory() + ", tot=" + runtime.totalMemory() + ", max=" + runtime.maxMemory());

                 Logger.logTextResource(
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

      this.mbeanServer = MBeanServerFactory.createMBeanServer();//("org.xmlBlaster");

      List list = ManagementFactory.getMemoryPoolMXBeans();
      Iterator it = list.iterator();
      while (it.hasNext()) {
         MemoryPoolMXBean tmpPool = (MemoryPoolMXBean)it.next();
         if (tmpPool.isUsageThresholdSupported() && tmpPool.getType().equals(MemoryType.HEAP)) {
            this.pool = tmpPool;
            // "Tenured Gen" = pool.getName()
            long myThreshold = (long)(this.thresholdFactor * (double)this.pool.getUsage().getMax()); //getCommitted());
            this.pool.setUsageThreshold(myThreshold);
            //System.out.println("Adding maxJvmMemory=" + maxJvmMemory() +
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

         try {
            String notifType = notification.getType();
            if (!notifType.equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED))
               return;

            MemoryPoolMXBean pool = (MemoryPoolMXBean)handback;

            int numTries = 5;
            for (int i=0; i<numTries; i++) {
               // Memory is low! maxJvmMemory=8.323 MBytes, max for heap=7.340 MBytes, otherMem=983040, threshold reached=6.606 MBytes,
               // Runtime.totalMemory=8323072, Runtime.freeMemory=1461904, usedMem=6.861 MBytes
               if (log.isLoggable(Level.FINE))
                  log.fine(
                  "Memory is low! maxJvmMemory=" + Global.byteString(LowMemoryDetector.maxJvmMemory()) +
                  ", max for heap=" + Global.byteString(pool.getUsage().getMax()) +
                  ", otherMem=" + Global.byteString(LowMemoryDetector.maxJvmMemory() - pool.getUsage().getMax()) // 8.323-7.340=0.983
                  ", threshold reached=" + Global.byteString(pool.getUsageThreshold()) +
                  ", Runtime.totalMemory=" + Global.byteString(Runtime.getRuntime().totalMemory()) +
                  ", Runtime.freeMemory=" + Global.byteString(Runtime.getRuntime().freeMemory()) +
                  ", usedMem=" + Global.byteString(Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()));

               System.gc();
               try { Thread.sleep(1); } catch (Exception e) {}

               long usedMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
               if (usedMem < pool.getUsageThreshold()) {
                  if (log.isLoggable(Level.FINE))
                     log.fine("Low memory: Nothing to do, the garbage collector has handled it usedMem=" + Global.byteString(usedMem) + " threshold=" + Global.byteString(pool.getUsageThreshold()));
                  return// Nothing to do, the garbage collector has handled it
               }
            }

            long usedMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());

            //Memory is low! maxJvmMemory=8.323 MBytes, committed for heap=7.340 MBytes, max for heap=7.340 MBytes,
            //threshold reached=6.606 MBytes, currently used=7.595 MBytes, count=2.
            //Physical RAM size is 1.060 GBytes, this JVM may use max 8.323 MBytes and max 1024 file descriptors
            log.severe("Memory is low! maxJvmMemory=" + Global.byteString(LowMemoryDetector.maxJvmMemory()) +
               //", committed for heap=" + Global.byteString(pool.getUsage().getCommitted()) +
               ", max for heap=" + Global.byteString(pool.getUsage().getMax()) +
               ", threshold reached=" + Global.byteString(pool.getUsageThreshold()) +
               ", currently used=" + Global.byteString(usedMem) +
               ", count=" + pool.getUsageThresholdCount() +
               ". Physical RAM size is " + Global.byteString(Global.totalPhysicalMemorySize) + "," +
               " this JVM may use max " + Global.byteString(Global.heapMemoryUsage) +
               " and max " + Global.maxFileDescriptorCount + " file descriptors");
            if (this.exitOnThreshold) {
               System.gc();
               try { Thread.sleep(1); } catch (Exception e) {}
               System.gc();
               try { Thread.sleep(1); } catch (Exception e) {}
               usedMem = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory());
               if (usedMem > pool.getUsageThreshold()) {
                  log.severe("Exiting now because of low memory (see '-xmlBlaster/jmx/exitOnMemoryThreshold true'");
                  System.exit(-9);
               }
               log.info("Garbage collected to usedMem=" + Global.byteString(usedMem) + ", we continue");
            }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    private boolean firstCollectionThreshExceededLogged = false;
   
    public SpillableMemoryManager() {
        ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
        List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
        MemoryPoolMXBean biggestHeap = null;
        long biggestSize = 0;
        for (MemoryPoolMXBean b: mpbeans) {
            log.debug("Found heap (" + b.getName() +
                ") of type " + b.getType());
            if (b.getType() == MemoryType.HEAP) {
                /* Here we are making the leap of faith that the biggest
                 * heap is the tenured heap
                 */
                long size = b.getUsage().getMax();
                if (size > biggestSize) {
                    biggestSize = size;
                    biggestHeap = b;
                }
            }
        }
        if (biggestHeap == null) {
            throw new RuntimeException("Couldn't find heap");
        }
        log.debug("Selected heap to monitor (" +
            biggestHeap.getName() + ")");
       
        // we want to set both collection and usage threshold alerts to be
        // safe. In some local tests after a point only collection threshold
        // notifications were being sent though usage threshold notifications
        // were sent early on. So using both would ensure that
        // 1) we get notified early (though usage threshold exceeded notifications)
        // 2) we get notified always when threshold is exceeded (either usage or
        //    collection)
       
        /* We set the threshold to be 50% of tenured since that is where
         * the GC starts to dominate CPU time according to Sun doc */
        biggestHeap.setCollectionUsageThreshold((long)(biggestSize * collectionMemoryThresholdFraction));
        // we set a higher threshold for usage threshold exceeded notification
        // since this is more likely to be effective sooner and we do not
        // want to be spilling too soon
        biggestHeap.setUsageThreshold((long)(biggestSize * memoryThresholdFraction));
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

        }

        for (ModelNode node : mps) {
            DescribedResource describedResource = basicResourceTest("memory-pool", node.asString());

            MemoryPoolMXBean mbean = mbeans.get(describedResource.resource.get("name").asString());
            Assert.assertNotNull(mbean);

            boolean usageSupported = describedResource.resource.get("usage-threshold-supported").asBoolean();
            Assert.assertEquals(mbean.isUsageThresholdSupported(), usageSupported);
            boolean collUsageSupported = describedResource.resource.get("collection-usage-threshold-supported").asBoolean();
            Assert.assertEquals(mbean.isCollectionUsageThresholdSupported(), collUsageSupported);

            ModelNode op = getOperation("reset-peak-usage", "memory-pool", node.asString());
            Assert.assertFalse(executeOp(op, false).isDefined());

            op = getOperation("write-attribute", "memory-pool", node.asString());
            op.get("name").set("usage-threshold");
            op.get("value").set(1024 * 100);
            ModelNode result = executeOp(op, !usageSupported);
            if (usageSupported) {
                Assert.assertEquals(1024 * 100, mbean.getUsageThreshold());
            }

            op = getOperation("write-attribute", "memory-pool", node.asString());
            op.get("name").set("collection-usage-threshold");
            op.get("value").set(1024 * 100);
            result = executeOp(op, !collUsageSupported);
            if (collUsageSupported) {
                Assert.assertEquals(1024 * 100, mbean.getCollectionUsageThreshold());
            }
        }
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    private static double collectionMemoryThresholdFraction = 0.5;
       
    public SpillableMemoryManager() {
        ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
        List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
        MemoryPoolMXBean biggestHeap = null;
        long biggestSize = 0;
        for (MemoryPoolMXBean b: mpbeans) {
            log.debug("Found heap (" + b.getName() +
                ") of type " + b.getType());
            if (b.getType() == MemoryType.HEAP) {
                /* Here we are making the leap of faith that the biggest
                 * heap is the tenured heap
                 */
                long size = b.getUsage().getMax();
                if (size > biggestSize) {
                    biggestSize = size;
                    biggestHeap = b;
                }
            }
        }
        if (biggestHeap == null) {
            throw new RuntimeException("Couldn't find heap");
        }
        log.debug("Selected heap to monitor (" +
            biggestHeap.getName() + ")");
       
        // we want to set both collection and usage threshold alerts to be
        // safe. In some local tests after a point only collection threshold
        // notifications were being sent though usage threshold notifications
        // were sent early on. So using both would ensure that
        // 1) we get notified early (though usage threshold exceeded notifications)
        // 2) we get notified always when threshold is exceeded (either usage or
        //    collection)
       
        /* We set the threshold to be 50% of tenured since that is where
         * the GC starts to dominate CPU time according to Sun doc */
        biggestHeap.setCollectionUsageThreshold((long)(biggestSize * collectionMemoryThresholdFraction));
        // we set a higher threshold for usage threshold exceeded notification
        // since this is more likely to be effective sooner and we do not
        // want to be spilling too soon
        biggestHeap.setUsageThreshold((long)(biggestSize * memoryThresholdFraction));
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    private static double collectionMemoryThresholdFraction = 0.5;
       
    public SpillableMemoryManager() {
        ((NotificationEmitter)ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
        List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
        MemoryPoolMXBean biggestHeap = null;
        long biggestSize = 0;
        for (MemoryPoolMXBean b: mpbeans) {
            log.debug("Found heap (" + b.getName() +
                ") of type " + b.getType());
            if (b.getType() == MemoryType.HEAP) {
                /* Here we are making the leap of faith that the biggest
                 * heap is the tenured heap
                 */
                long size = b.getUsage().getMax();
                if (size > biggestSize) {
                    biggestSize = size;
                    biggestHeap = b;
                }
            }
        }
        if (biggestHeap == null) {
            throw new RuntimeException("Couldn't find heap");
        }
        log.debug("Selected heap to monitor (" +
            biggestHeap.getName() + ")");
       
        // we want to set both collection and usage threshold alerts to be
        // safe. In some local tests after a point only collection threshold
        // notifications were being sent though usage threshold notifications
        // were sent early on. So using both would ensure that
        // 1) we get notified early (though usage threshold exceeded notifications)
        // 2) we get notified always when threshold is exceeded (either usage or
        //    collection)
       
        /* We set the threshold to be 50% of tenured since that is where
         * the GC starts to dominate CPU time according to Sun doc */
        biggestHeap.setCollectionUsageThreshold((long)(biggestSize * collectionMemoryThresholdFraction));
        // we set a higher threshold for usage threshold exceeded notification
        // since this is more likely to be effective sooner and we do not
        // want to be spilling too soon
        biggestHeap.setUsageThreshold((long)(biggestSize * memoryThresholdFraction));
    }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

        return PlatformMBeanDescriptions.getDescriptionOnlyOperation(locale, PlatformMBeanConstants.MEMORY_POOL + ".reset-peak-usage");
    }

    private MemoryPoolMXBean getMemoryPoolMXBean(ModelNode operation) throws OperationFailedException {
        final String gcName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
        MemoryPoolMXBean memoryPoolMXBean = null;

        for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
            if (gcName.equals(escapeMBeanName(mbean.getName()))) {
                memoryPoolMXBean = mbean;
            }
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    @Override
    public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {

        final String memPoolName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();

        MemoryPoolMXBean memoryPoolMXBean = MemoryPoolMXBeanAttributeHandler.getMemoryPoolMXBean(memPoolName);

        final ModelNode result = context.getResult();

        for (String attribute : PlatformMBeanConstants.MEMORY_POOL_READ_ATTRIBUTES) {
            final ModelNode store = result.get(attribute);
View Full Code Here

Examples of java.lang.management.MemoryPoolMXBean

    }

    static MemoryPoolMXBean getMemoryPoolMXBean(String memPoolName) throws OperationFailedException {

        MemoryPoolMXBean memoryPoolMXBean = null;

        for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
            if (memPoolName.equals(escapeMBeanName(mbean.getName()))) {
                memoryPoolMXBean = mbean;
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.