Package java.lang.management

Examples of java.lang.management.MemoryMXBean


    * @param mof - the ManagedObjectFactory to use
    * @return
    */
   public static ManagedObject getMemoryMXBean(ManagedObjectFactory mof)
   {
      MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
      ManagedObject mo = getMO(mbean, MemoryMXBeanMO.class, mof);
      return mo;
   }
View Full Code Here


  private static final Logger logger = LoggerFactory.getLogger(BasicMonitor.class);

  public void logStats() {
    ThreadMXBean threads = ManagementFactory.getThreadMXBean();
    MemoryMXBean memory = ManagementFactory.getMemoryMXBean();

    checkDeadlocks(threads);
    logger.info("[Used {}M/Max {}M] [Threads {}]",
        new Object[] {
            memory.getHeapMemoryUsage().getUsed() / (1024 * 1024),
            memory.getHeapMemoryUsage().getMax() / (1024 * 1024),
            threads.getThreadCount() });
  }
View Full Code Here

  public interface Listener {
    public void memoryUsageLow(long usedMemory, long maxMemory);
  }

  private MemoryMonitor() {
    final MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(new NotificationListener() {
      public void handleNotification(Notification n, Object hb) {
        if (n.getType()
            .equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
View Full Code Here

    // TODO (jon) gc

    // TODO (jon) mem man

    // mem
    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = mem.getHeapMemoryUsage();
    rpt.setLongMetric("mem.heap.used", heap.getUsed());
    rpt.setLongMetric("mem.heap.init", heap.getInit());
    rpt.setLongMetric("mem.heap.max", heap.getMax());
    rpt.setLongMetric("mem.heap.committed", heap.getCommitted());

    MemoryUsage notheap = mem.getNonHeapMemoryUsage();
    rpt.setLongMetric("mem.other.used", notheap.getUsed());
    rpt.setLongMetric("mem.other.init", notheap.getInit());
    rpt.setLongMetric("mem.other.max", notheap.getMax());
    rpt.setLongMetric("mem.other.committed", notheap.getCommitted());
View Full Code Here

  static String getInodeLimitText(FSNamesystem fsn) {
    long inodes = fsn.dir.totalInodes();
    long blocks = fsn.getBlocksTotal();
    long maxobjects = fsn.getMaxObjects();

    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = mem.getHeapMemoryUsage();
    long totalMemory = heap.getUsed();
    long maxMemory = heap.getMax();
    long commitedMemory = heap.getCommitted();
   
    MemoryUsage nonHeap = mem.getNonHeapMemoryUsage();
    long totalNonHeap = nonHeap.getUsed();
    long maxNonHeap = nonHeap.getMax();
    long commitedNonHeap = nonHeap.getCommitted();

    long used = (totalMemory * 100) / commitedMemory;
View Full Code Here

        Map<String, String> props = new HashMap<String, String>();

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

        //
        // print ServiceMix informations
        //
        maxNameLen = 25;
        io.out.println("ServiceMix");
        printValue("ServiceMix home", maxNameLen, System.getProperty("servicemix.home"));
        printValue("ServiceMix base", maxNameLen, System.getProperty("servicemix.base"));
        printValue("ServiceMix version", maxNameLen, branding.getVersion());
        io.out.println();

        io.out.println("JVM");
        printValue("Java Virtual Machine", maxNameLen, runtime.getVmName() + " version " + runtime.getVmVersion());
        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()));

        io.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()));

        io.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

    long inodes = fsn.dir.totalInodes();
    long blocks = fsn.getBlocksTotal();
    long maxobjects = fsn.getMaxObjects();

    MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
    MemoryUsage heap = mem.getHeapMemoryUsage();
    long totalMemory = heap.getUsed();
    long maxMemory = heap.getMax();
    long commitedMemory = heap.getCommitted();
   
    MemoryUsage nonHeap = mem.getNonHeapMemoryUsage();
    long totalNonHeap = nonHeap.getUsed();
    long maxNonHeap = nonHeap.getMax();
    long commitedNonHeap = nonHeap.getCommitted();

    long used = (totalMemory * 100) / commitedMemory;
View Full Code Here

    /*
     * Test method for
     * 'java.lang.management.ManagementFactory.getMemoryMXBean()'
     */
    public void testGetMemoryMXBean() {
        MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
        assertNotNull(mb);

        // Verify that there is only instance of this bean
        MemoryMXBean mb2 = ManagementFactory.getMemoryMXBean();
        assertNotNull(mb2);
        assertSame(mb, mb2);
    }
View Full Code Here

     * Test method for
     * 'java.lang.management.ManagementFactory.newPlatformMXBeanProxy(MBeanServerConnection,
     * String, Class<T>) <T>'
     */
    public void testNewPlatformMXBeanProxy_MemoryMXBean() throws Exception {
        MemoryMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(
                ManagementFactory.getPlatformMBeanServer(),
                "java.lang:type=Memory", MemoryMXBean.class);
        assertNotNull(proxy);
        MemoryMXBean mb = ManagementFactory.getMemoryMXBean();
        // RI's MemoryUsage does not appear to override equals() so we have to
        // go the long way round to check that the answers match...
        MemoryUsage mu1 = mb.getHeapMemoryUsage();
        MemoryUsage mu2 = proxy.getHeapMemoryUsage();
        assertEquals(mu1.getInit(), mu2.getInit());
        assertEquals(mu1.getMax(), mu2.getMax());

        mu1 = mb.getNonHeapMemoryUsage();
        mu2 = proxy.getNonHeapMemoryUsage();
        assertEquals(mu1.getInit(), mu2.getInit());
        assertEquals(mu1.getMax(), mu2.getMax());

        assertEquals(mb.isVerbose(), proxy.isVerbose());
        // changes made to proxy should be seen in the "real bean" and
        // vice versa
        boolean initialValue = proxy.isVerbose();
        mb.setVerbose(!initialValue);
        assertEquals(!initialValue, proxy.isVerbose());
        proxy.setVerbose(initialValue);
        assertEquals(initialValue, mb.isVerbose());
    }
View Full Code Here

    utcOffset = zone.getRawOffset();
    useDST = zone.useDaylightTime();
    startupDateTime = new Date(System.currentTimeMillis());
    availableProcessors = Runtime.getRuntime().availableProcessors();

    MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
    memBean.getHeapMemoryUsage();
    File[] roots = File.listRoots();
    for (int i = 0; i < roots.length; i++) {
      availableDiskSpace += roots[i].getFreeSpace();
    }
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.