Example usage for java.lang.management ManagementFactory getRuntimeMXBean

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

Introduction

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

Prototype

public static RuntimeMXBean getRuntimeMXBean() 

Source Link

Document

Returns the managed bean for the runtime system of the Java virtual machine.

Usage

From source file:com.alibaba.dragoon.client.jmx.Threading.java

public Threading() {
    Threading = ManagementFactory.getThreadMXBean();
    OperatingSystem = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    Runtime = ManagementFactory.getRuntimeMXBean();

    try {/*from   ww  w. j a  v a2 s. c o  m*/
        gc = new GC();

        // ?
        lastGCTime = gc.getFullGCCollectionTime() + gc.getYoungGCCollectionTime();
        lastCPUTime = getProcessCpuTime();
        lastGCUpTime = lastCPUUpTime = getUpTime();

    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
}

From source file:com.amazonaws.services.simpleworkflow.flow.worker.GenericWorkflowWorker.java

public GenericWorkflowWorker() {
    setIdentity(ManagementFactory.getRuntimeMXBean().getName());
}

From source file:com.mgmtp.perfload.agent.Agent.java

static int retrievePid() {
    try {/*from  w ww .j ava  2 s  .c  o m*/
        // There is no SecurityManager involved retrieving this bean,
        // but just to be safe, we catch exceptions.
        String jvmName = ManagementFactory.getRuntimeMXBean().getName();
        Matcher matcher = Pattern.compile("\\d*").matcher(jvmName);
        return matcher.find() ? Integer.parseInt(matcher.group()) : -1;
    } catch (Exception ex) {
        System.err.println("Error retrieving process id.");
        ex.printStackTrace();
        return -1;
    }
}

From source file:org.nuclos.common.startup.Startup.java

@Override
public void afterPropertiesSet() throws Exception {
    final TimerTask task = new TimerTask() {

        @Override/*w ww .  ja  v a  2 s.c o m*/
        public void run() {
            try {
                final RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
                final List<String> arguments = RuntimemxBean.getInputArguments();
                LOG.info("server started with " + arguments);

                final String version = IOUtils.toString(getClasspathResource("nuclos-version.properties"),
                        ENCODING);
                LOG.info("version info\n:" + version);
                final String info = IOUtils.toString(getClasspathResource("info.txt"), ENCODING);
                LOG.info("SVN info\n:" + info);
                final String status = IOUtils.toString(getClasspathResource("status.txt"), ENCODING);
                LOG.info("SVN status\n:" + status);
            } catch (Exception e) {
                LOG.info("Startup timer task failed: " + e);
            }
        }
    };
    timer.schedule(task, 500);
}

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

@Override
public void appendInformation(InformationStringBuilder infoCollector) {
    osInfo(ManagementFactory.getOperatingSystemMXBean(), infoCollector);
    runtimeInfo(ManagementFactory.getRuntimeMXBean(), infoCollector);
    gcInfo(ManagementFactory.getGarbageCollectorMXBeans(), infoCollector);
    memoryInfo(ManagementFactory.getMemoryMXBean(), infoCollector);
    poolInfo(infoCollector);//ww  w  .  ja v a  2  s  . c  o m
    threadInfo(ManagementFactory.getThreadMXBean(), infoCollector);
}

From source file:com.l2jfree.L2Config.java

/**
 * Returns application lifetime in an user-friendly string.
 * //  w  w  w. ja  va2s .  c  o  m
 * @return time since launch
 */
public static String getUptime() {
    final long uptimeInSec = (long) Math.ceil(ManagementFactory.getRuntimeMXBean().getUptime() / 1000.0);

    final long s = uptimeInSec / 1 % 60;
    final long m = uptimeInSec / 60 % 60;
    final long h = uptimeInSec / 3600 % 24;
    final long d = uptimeInSec / 86400;

    final L2TextBuilder tb = new L2TextBuilder();

    if (d > 0)
        tb.append(d + " day(s), ");

    if (h > 0 || tb.length() != 0)
        tb.append(h + " hour(s), ");

    if (m > 0 || tb.length() != 0)
        tb.append(m + " minute(s), ");

    if (s > 0 || tb.length() != 0)
        tb.append(s + " second(s)");

    return tb.moveToString();
}

From source file:jetbrains.exodus.util.ForkedProcessRunner.java

private static String getProcessId() {
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    String name = runtimeBean.getName();
    return name.substring(0, name.indexOf('@')); // yes, it's not documented, but name has form "PID@bullshit"
}

From source file:com.microsoft.applicationinsights.internal.system.SystemInformation.java

private synchronized void setProcessId() {
    if (!Strings.isNullOrEmpty(processId)) {
        return;/* www .j  av a2s  . c o m*/
    }

    String rawName = ManagementFactory.getRuntimeMXBean().getName();
    if (!Strings.isNullOrEmpty(rawName)) {
        int i = rawName.indexOf("@");
        if (i != -1) {
            String processIdAsString = rawName.substring(0, i);
            try {
                Integer.parseInt(processIdAsString);
                processId = processIdAsString;
                return;
            } catch (Exception e) {
                InternalLogger.INSTANCE.error("Failed to fetch process id: '%s'", e.getMessage());
            }
        }
    }

    // Default
    processId = DEFAULT_PROCESS_NAME;
}

From source file:net.openhft.chronicle.VanillaChronicleTestBase.java

protected String getPIDAsString() {
    final String name = ManagementFactory.getRuntimeMXBean().getName();
    return name.split("@")[0];
}

From source file:org.apache.gobblin.kafka.writer.Kafka09TopicProvisionTest.java

@BeforeSuite
public void beforeSuite() {
    log.info("Process id = " + ManagementFactory.getRuntimeMXBean().getName());
    _kafkaTestHelper.startCluster();
}