Example usage for java.lang.management MemoryMXBean getObjectPendingFinalizationCount

List of usage examples for java.lang.management MemoryMXBean getObjectPendingFinalizationCount

Introduction

In this page you can find the example usage for java.lang.management MemoryMXBean getObjectPendingFinalizationCount.

Prototype

public int getObjectPendingFinalizationCount();

Source Link

Document

Returns the approximate number of objects for which finalization is pending.

Usage

From source file:it.geosolutions.geobatch.ui.mvc.MemoryController.java

@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ModelAndView mav = new ModelAndView("memory"); // jsp
    final MemoryMXBean mmxbean = ManagementFactory.getMemoryMXBean();
    mav.addObject("objectPendingFinalizationCount", mmxbean.getObjectPendingFinalizationCount());
    mav.addObject("nonHeapMemoryUsage", mmxbean.getNonHeapMemoryUsage());
    mav.addObject("heapMemoryUsage", mmxbean.getHeapMemoryUsage());
    mav.addObject("memoryPoolBeansList", ManagementFactory.getMemoryPoolMXBeans());

    return mav;/*from   w  ww.  j av a  2 s.c  o  m*/
}

From source file:it.damore.tomee.envmonitor.services.EnvMonitorService.java

@GET
@Path("monitor")
@Produces({ MediaType.APPLICATION_JSON })
public EnvironmentConfig getEnvConfig() throws IllegalAccessException, InvocationTargetException {
    logger.info("received a request...");

    int mb = 1024 * 1024;
    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();

    EnvironmentConfig b = new EnvironmentConfig();
    b.setMaxMemory(runtime.maxMemory() / mb);
    b.setFreeMemory(runtime.freeMemory() / mb);
    b.setTotalMemory(runtime.totalMemory() / mb);
    b.setSystemProperties(System.getProperties());

    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    LocalRuntimeMXBean myRuntimeMXBean = new LocalRuntimeMXBean();
    BeanUtils.copyProperties(myRuntimeMXBean, runtimeMXBean);
    b.setRuntimeMXBean(myRuntimeMXBean);

    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    LocalMemoryMXBean myMemoryMXBean = new LocalMemoryMXBean();
    myMemoryMXBean.setHeapMemoryUsage(memoryMXBean.getHeapMemoryUsage());
    myMemoryMXBean.setNonHeapMemoryUsage(memoryMXBean.getNonHeapMemoryUsage());
    myMemoryMXBean.setObjectPendingFinalizationCount(memoryMXBean.getObjectPendingFinalizationCount());
    b.setMemoryMXBean(myMemoryMXBean);/*  w w w  .jav  a2 s  .c  om*/

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    LocalOperatingSystemMXBean myOperatingSystemMXBean = new LocalOperatingSystemMXBean();
    BeanUtils.copyProperties(myOperatingSystemMXBean, operatingSystemMXBean);
    b.setOperatingSystemMXBean(myOperatingSystemMXBean);

    return b;
}

From source file:com.thoughtworks.go.server.service.support.ServerRuntimeInformationProvider.java

private void memoryInfo(MemoryMXBean memoryMXBean, InformationStringBuilder builder) {
    builder.addSection("Memory information");

    builder.append(String.format("Heap:\n%s\nNon-Heap:\n%s\nPending Finalization: %s\n",
            format(memoryMXBean.getHeapMemoryUsage()), format(memoryMXBean.getNonHeapMemoryUsage()),
            memoryMXBean.getObjectPendingFinalizationCount()));
}

From source file:org.commoncrawl.util.JVMStats.java

public static void dumpMemoryStats() {

    MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
    MemoryUsage memHeap = memoryMXBean.getHeapMemoryUsage();

    List<GarbageCollectorMXBean> gcBeans = ManagementFactory.getGarbageCollectorMXBeans();

    long gcTime = 0;
    for (GarbageCollectorMXBean gcBean : gcBeans) {
        gcTime += gcBean.getCollectionTime();
    }//from  ww  w.ja v  a 2 s .com

    float utilizationRatio = ((float) memHeap.getUsed()) / ((float) memHeap.getMax());

    LOG.info("Heap Size:" + memHeap.getUsed() / MBytes + " (MB) CommitSize:" + memHeap.getCommitted() / MBytes
            + " (MB) Max:" + memHeap.getMax() + " Ratio:" + utilizationRatio + " GCTime:"
            + (gcTime - lastGCTime) + "PendingFinalCnt:" + memoryMXBean.getObjectPendingFinalizationCount());

    lastGCTime = gcTime;
}

From source file:org.fluentd.jvmwatcher.data.JvmStateLog.java

/**
 * @param clientPrixy/* w  w  w  .  j  a v  a2s  .  com*/
 * @return
 */
public static JvmStateLog makeJvmStateLog(JvmClientProxy clientProxy) {
    JvmStateLog ret = new JvmStateLog();

    try {
        // set log time
        ret.logDateTime_ = System.currentTimeMillis();

        // ClassLoadingMXBean
        ClassLoadingMXBean classLoadingBean = clientProxy.getClassLoadingMXBean();
        if (null != classLoadingBean) {
            ret.classLoadedCount_ = classLoadingBean.getLoadedClassCount();
            ret.classUnloadedCount_ = classLoadingBean.getUnloadedClassCount();
            ret.classTotalLoadedCount_ = classLoadingBean.getTotalLoadedClassCount();
        }

        // CompilationMXBean
        CompilationMXBean compilationBean = clientProxy.getCompilationMXBean();
        if (null != compilationBean) {
            ret.compileTime_ = compilationBean.getTotalCompilationTime();
        }

        // MemoryMXBean
        MemoryMXBean memoryBean = clientProxy.getMemoryMXBean();
        if (null != memoryBean) {
            ret.heapSize_ = memoryBean.getHeapMemoryUsage();
            ret.notheapSize_ = memoryBean.getNonHeapMemoryUsage();
            ret.pendingFinalizationCount_ = memoryBean.getObjectPendingFinalizationCount();
        }

        // ThreadMXBean
        ThreadMXBean threadBean = clientProxy.getThreadMXBean();
        if (null != threadBean) {
            ret.threadCount_ = threadBean.getThreadCount();
            ret.daemonThreadCount_ = threadBean.getDaemonThreadCount();
            ret.peakThreadCount_ = threadBean.getPeakThreadCount();
        }

        // OperatingSystemMXBean
        OperatingSystemMXBean OpeSysBean = clientProxy.getOperatingSystemMXBean();
        if (null != OpeSysBean) {
            ret.osAvailableProcessors_ = OpeSysBean.getAvailableProcessors();
            ret.osSystemLoadAverage_ = OpeSysBean.getSystemLoadAverage();
        }

        // com.sun.management.OperatingSystemMXBean
        com.sun.management.OperatingSystemMXBean sunOpeSysBean = clientProxy.getSunOperatingSystemMXBean();
        if (null != sunOpeSysBean) {
            ret.committedVirtualMemorySize_ = sunOpeSysBean.getCommittedVirtualMemorySize();
            ret.freePhysicalMemorySize_ = sunOpeSysBean.getFreePhysicalMemorySize();
            ret.freeSwapSpaceSize_ = sunOpeSysBean.getFreeSwapSpaceSize();
            ret.processCpuTime_ = sunOpeSysBean.getProcessCpuTime();
            ret.totalPhysicalMemorySize_ = sunOpeSysBean.getTotalPhysicalMemorySize();
            ret.totalSwapSpaceSize_ = sunOpeSysBean.getTotalSwapSpaceSize();
        }

        // RuntimeMXBean
        RuntimeMXBean runtimeBean = clientProxy.getRuntimeMXBean();
        if (null != runtimeBean) {
            ret.jvmUpTime_ = runtimeBean.getUptime();
        }

        // MemoryPoolMXBean
        Collection<MemoryPoolClientProxy> memoryPoolBeansColl = clientProxy.getMemoryPoolClientProxies();
        if (null != memoryPoolBeansColl) {
            ret.memoryPoolStateColl_ = new ArrayList<MemoryPoolState>();
            for (MemoryPoolClientProxy elem : memoryPoolBeansColl) {
                if (null != elem) {
                    MemoryPoolState state = elem.getStat();
                    if (null != state) {
                        // add MemoryPoolState
                        ret.memoryPoolStateColl_.add(state);
                    }
                }
            }
        }

        // GarbageCollectorMXBean
        Collection<GarbageCollectorMXBean> garbageCollBeansColl = clientProxy.getGarbageCollectorMXBeans();
        if (null != garbageCollBeansColl) {
            ret.gcCollectorState_ = new ArrayList<GarbageCollectorState>();
            for (GarbageCollectorMXBean elem : garbageCollBeansColl) {
                if (null != elem) {
                    long collectionCount = elem.getCollectionCount();
                    long collectionTime = elem.getCollectionTime();
                    String memoryManagerName = elem.getName();
                    GarbageCollectorState state = new GarbageCollectorState(memoryManagerName, collectionCount,
                            collectionTime);
                    // add GarbageCollectorState
                    ret.gcCollectorState_.add(state);
                }
            }
        }
    } catch (IOException ex) {
        log.error(ex);
        // close JvmClientProxy
        clientProxy.disconnect();
    } catch (Exception ex) {
        log.error(ex);
        // close JvmClientProxy
        clientProxy.disconnect();
    }

    return ret;
}

From source file:org.liferayhub.pc.service.impl.PowerConsoleServiceImpl.java

public String runCommand(long userId, long companyId, String mode, String command) {
    String response = "";
    Date startDate = new Date();
    if ("server".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\t\tShow this help message\n"
                    + "version\t\t Display the version of the Liferay Portal\n"
                    + "date\t\t\tDisplay the date and time of the database server\n"
                    + "uptime\t\t  Display the uptime of the portal\n" + "adduser\t\t Add a new user";
        } else if ("version".equalsIgnoreCase(command)) {
            response = ReleaseInfo.getReleaseInfo() + " running on "
                    + StringUtil.upperCaseFirstLetter(ServerDetector.getServerId());
        } else if ("date".equalsIgnoreCase(command)) {
            response = new Date().toString();
        } else if ("uptime".equalsIgnoreCase(command)) {
            response = getUptime(PortalUtil.getUptime().getTime());
        } else if (command.toLowerCase().startsWith("adduser")) {
            response = handleAddUser(userId, companyId, command);
        }/* www  .j  av  a2s .c  om*/
    } else if ("db".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\t\tShow this help message\n"
                    + "version\t\t Display the version of the database\n"
                    + "date\t\t\tDisplay the date and time of the database server\n"
                    + "<sql query>\t Display result of any SQL query";
        } else if ("date".equalsIgnoreCase(command)) {
            response = runSQLQuery("select now() \"\"");
        } else if ("version".equalsIgnoreCase(command)) {
            response = runSQLQuery(
                    "select '" + DBFactoryUtil.getDBFactory().getDB().getType() + "' as '', version() ''");
        } else
            response = runSQLQuery(command);
    } else if ("jvm".equalsIgnoreCase(mode)) {
        if ("help".equalsIgnoreCase(command)) {
            response = "Commands:\n" + "help\t\tShow this help message\n"
                    + "mem\t\t Display memory usage of the JVM\n"
                    + "osinfo\t  Display operating system info of the running JVM\n"
                    + "vminfo\t  Display VM info";
        } else if ("mem".equalsIgnoreCase(command)) {
            MemoryMXBean mem = ManagementFactory.getMemoryMXBean();
            response = "Heap        : " + mem.getHeapMemoryUsage().toString();
            response += "\nNon Heap    : " + mem.getNonHeapMemoryUsage().toString();
            response += "\nFinalization: " + mem.getObjectPendingFinalizationCount() + " objects pending";
        } else if ("osinfo".equalsIgnoreCase(command)) {
            OperatingSystemMXBean os = ManagementFactory.getOperatingSystemMXBean();
            response = os.getName() + "[" + os.getArch() + "] " + os.getVersion() + " ("
                    + os.getAvailableProcessors() + " processors)";
            response += "\nLoad Average: " + os.getSystemLoadAverage();
        } else if ("vminfo".equalsIgnoreCase(command)) {
            RuntimeMXBean vm = ManagementFactory.getRuntimeMXBean();
            response = vm.getVmName() + " " + vm.getVmVersion() + " by " + vm.getVmVendor();
            response += "\n" + vm.getSpecName() + " " + vm.getSpecVersion() + " by " + vm.getSpecVendor();
            response += "\nStarted at: " + DateFormat.getInstance().format(new Date(vm.getStartTime()));
            response += "\nUptime    : " + getUptime(vm.getStartTime());
        } else {
            response = UNRECOGNIZED_COMMAND;
        }
    }
    // save command to database if it is not 'help'
    if (!command.startsWith("help")) {
        try {
            // add to history
            Date endDate = new Date();
            long id = CounterLocalServiceUtil.increment(CommandHistory.class.getName());
            CommandHistory history = CommandHistoryLocalServiceUtil.createCommandHistory(id);
            history.setCommand(command);
            history.setExecutionDate(startDate);
            history.setExecutionTime(endDate.getTime() - startDate.getTime());
            history.setMode(mode);
            history.setUserId(userId);
            CommandHistoryLocalServiceUtil.updateCommandHistory(history);
            // TODO: delete the oldest entry > MAX_HISTORY_SIZE
            // get the history size
            long historySize = 100;
            List<CommandHistory> historyList = CommandHistoryLocalServiceUtil
                    .findCommandHistoryByUserId(userId);
            if (historyList.size() >= historySize) {
                CommandHistoryLocalServiceUtil.deleteCommandHistory(historyList.get(0));
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e.getMessage());
        }
    }
    return response;
}