Example usage for java.lang.management ManagementFactory getClassLoadingMXBean

List of usage examples for java.lang.management ManagementFactory getClassLoadingMXBean

Introduction

In this page you can find the example usage for java.lang.management ManagementFactory getClassLoadingMXBean.

Prototype

public static ClassLoadingMXBean getClassLoadingMXBean() 

Source Link

Document

Returns the managed bean for the class loading system of the Java virtual machine.

Usage

From source file:com.example.config.BeanCountingApplicationListener.java

@SuppressWarnings("resource")
@Override//from  ww w.jav  a 2  s.c o  m
public void onApplicationEvent(ApplicationReadyEvent event) {
    if (!event.getApplicationContext().equals(this.context)) {
        return;
    }
    int count = 0;
    ConfigurableApplicationContext context = event.getApplicationContext();
    String id = context.getId();
    List<String> names = new ArrayList<>();
    while (context != null) {
        count += context.getBeanDefinitionCount();
        names.addAll(Arrays.asList(context.getBeanDefinitionNames()));
        context = (ConfigurableApplicationContext) context.getParent();
    }
    logger.info("Bean count: " + id + "=" + count);
    logger.debug("Bean names: " + id + "=" + names);
    try {
        logger.info("Class count: " + id + "="
                + ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
    } catch (Exception e) {
    }
}

From source file:com.snowstore.mercury.core.metric.SystemPublicMetrics.java

/**
 * Add class loading metrics./*from ww w.  j a va2 s .  c  o m*/
 * 
 * @param result
 *            the result
 */
protected void addClassLoadingMetrics(Collection<Metric<?>> result) {
    ClassLoadingMXBean classLoadingMxBean = ManagementFactory.getClassLoadingMXBean();
    result.add(new Metric<Long>("classes", (long) classLoadingMxBean.getLoadedClassCount()));
    result.add(new Metric<Long>("classes.loaded", classLoadingMxBean.getTotalLoadedClassCount()));
    result.add(new Metric<Long>("classes.unloaded", classLoadingMxBean.getUnloadedClassCount()));
}

From source file:com.opengamma.web.WebAbout.java

/**
 * Gets the class loading JMX.
 * @return the class loading JMX
 */
public ClassLoadingMXBean getClassLoadingJmx() {
    return ManagementFactory.getClassLoadingMXBean();
}

From source file:com.eurelis.opencms.admin.systeminformation.CmsSystemInformationOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *///from  www  . j  av a2s  . c o  m
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    //JVM uptime
    Date date = new Date(runtimeBean.getUptime());
    java.text.SimpleDateFormat simpleFormatH = new java.text.SimpleDateFormat("HH");
    java.text.SimpleDateFormat simpleFormatM = new java.text.SimpleDateFormat("mm");
    java.text.SimpleDateFormat simpleFormatS = new java.text.SimpleDateFormat("ss");
    String jvmuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    //JVM start time
    date = new Date(runtimeBean.getStartTime());
    String jvmstarttimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    //OpenCms runtime
    date = new Date(OpenCms.getSystemInfo().getRuntime());
    String opencmsruntimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    //OpenCms startup time
    date = new Date(OpenCms.getSystemInfo().getStartupTime());
    String opencmsstartuptimestring = simpleFormatH.format(date) + "h " + simpleFormatM.format(date) + "min "
            + simpleFormatS.format(date) + "s ";

    setOperatingSystem("" + osBean.getName());
    setJavaVersion(System.getProperty("java.version"));
    setJvmUptime("" + jvmuptimestring);
    setJvmStarttime("" + jvmstarttimestring);
    setOpenCmsVersion(OpenCms.getSystemInfo().getVersionNumber());
    setOpenCmsRuntime("" + opencmsruntimestring);
    setOpenCmsStartupTime("" + opencmsstartuptimestring);

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

}

From source file:com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *///from   w w w  . j av a 2 s  .  c o  m
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    setCpuCount("" + osBean.getAvailableProcessors());
    double usage = com.eurelis.opencms.admin.systeminformation.CmsCPUThreadsClassesOverviewDialog
            .getCPUUsage(getSession());
    usage = Math.round(usage * 100) / 100;
    setCpuUsage("" + 100 * usage + "%");

    setLoadedClassesCount("" + classesBean.getLoadedClassCount());
    setUnloadedClassesCount("" + classesBean.getUnloadedClassCount());
    setTotalLoadedClassesCount("" + classesBean.getTotalLoadedClassCount());

    setThreadsCount("" + threadBean.getThreadCount());
    setThreadsStartedCount("" + threadBean.getTotalStartedThreadCount());
    setThreadsPeakCount("" + threadBean.getPeakThreadCount());
    setThreadsDaemonCount("" + threadBean.getDaemonThreadCount());

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

    setParamCloseLink(getJsp().link(
            "/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/cpu_and_threads.jsp"));

}

From source file:com.eurelis.opencms.admin.systeminformation.CmsMemoryOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *//*from www . j a va2  s  .c o  m*/
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    for (java.lang.management.MemoryPoolMXBean item : ManagementFactory.getMemoryPoolMXBeans()) {
        java.lang.management.MemoryUsage mu = item.getUsage();
        String name = item.getName();

        if (name.toLowerCase().contains("perm")) {
            setMemPermMax("" + mu.getMax());
            setMemPermTotal("" + mu.getCommitted());
            setMemPermUsed("" + mu.getUsed());
        } else if (name.toLowerCase().contains("old")) {
            setMemOldMax("" + mu.getMax());
            setMemOldTotal("" + mu.getCommitted());
            setMemOldUsed("" + mu.getUsed());
        } else if (name.toLowerCase().contains("eden")) {
            setMemEdenMax("" + mu.getMax());
            setMemEdenTotal("" + mu.getCommitted());
            setMemEdenUsed("" + mu.getUsed());
        } else if (name.toLowerCase().contains("survivor")) {
            setMemSurvivorMax("" + mu.getMax());
            setMemSurvivorTotal("" + mu.getCommitted());
            setMemSurvivorUsed("" + mu.getUsed());
        } else {
            //LOG.debug("MemoryPoolMXBean name = " + name.toLowerCase());
        }
    }

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

    setParamCloseLink(getJsp()
            .link("/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/memory.jsp"));
}

From source file:com.eurelis.opencms.admin.systeminformation.CmsDBPoolsOverviewDialog.java

/**
 * Initializes the infos object.<p>
 *//*from w w w.  ja va2s.c o  m*/
protected void initInfosObject() {

    com.sun.management.OperatingSystemMXBean sunOsBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    java.lang.management.OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    java.lang.management.ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
    java.lang.management.RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    java.lang.management.ClassLoadingMXBean classesBean = ManagementFactory.getClassLoadingMXBean();

    initPools();

    Object o;
    if (CmsStringUtil.isEmpty(getParamAction())) {
        o = new CmsAdminSettings(getSession());
    } else {
        // this is not the initial call, get the job object from session
        o = getDialogObject();
    }
    if (!(o instanceof CmsAdminSettings)) {
        // create a new history settings handler object
        m_adminSettings = new CmsAdminSettings(getSession());
    } else {
        // reuse html import handler object stored in session
        m_adminSettings = (CmsAdminSettings) o;
    }

    setParamCloseLink(getJsp().link(
            "/system/workplace/views/admin/admin-main.jsp?path=/eurelis_system_information/database_pools.jsp"));

}

From source file:org.apache.flink.runtime.metrics.util.MetricUtils.java

private static void instantiateClassLoaderMetrics(MetricGroup metrics) {
    final ClassLoadingMXBean mxBean = ManagementFactory.getClassLoadingMXBean();

    metrics.gauge("ClassesLoaded", new Gauge<Long>() {
        @Override//from w w  w .  j a  v  a2 s  . c o  m
        public Long getValue() {
            return mxBean.getTotalLoadedClassCount();
        }
    });
    metrics.gauge("ClassesUnloaded", new Gauge<Long>() {
        @Override
        public Long getValue() {
            return mxBean.getUnloadedClassCount();
        }
    });
}

From source file:org.springframework.samples.petclinic.system.BeanCountingApplicationListener.java

@SuppressWarnings("resource")
@Override//from www.  j av a2 s.c om
public void onApplicationEvent(ContextRefreshedEvent event) {
    if (!event.getApplicationContext().equals(this.context)) {
        return;
    }
    int count = 0;
    ConfigurableApplicationContext context = (ConfigurableApplicationContext) event.getApplicationContext();
    String id = context.getId();
    List<String> names = new ArrayList<>();
    while (context != null) {
        count += context.getBeanDefinitionCount();
        names.addAll(Arrays.asList(context.getBeanDefinitionNames()));
        context = (ConfigurableApplicationContext) context.getParent();
    }
    logger.info("Bean count: " + id + "=" + count);
    logger.debug("Bean names: " + id + "=" + names);
    try {
        logger.info("Class count: " + id + "="
                + ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
    } catch (Exception e) {
    }
}