Search in sources :

Example 51 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project Mycat-Server by MyCATApache.

the class EnvironmentInformation method getJvmStartupOptionsArray.

/**
	 * Gets the system parameters and environment parameters that were passed to the JVM on startup.
	 *
	 * @return The options passed to the JVM on startup.
	 */
public static String[] getJvmStartupOptionsArray() {
    try {
        RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
        List<String> options = bean.getInputArguments();
        return options.toArray(new String[options.size()]);
    } catch (Throwable t) {
        return new String[0];
    }
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 52 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project redisson by redisson.

the class RedissonTestRunListener method testRunStarted.

@Override
public void testRunStarted(Description description) throws Exception {
    super.testRunStarted(description);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        running.set(Boolean.FALSE);
    }));
    new Thread(() -> {
        final RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        final AtomicLong u = new AtomicLong(runtimeBean.getUptime());
        while (running.get()) {
            try {
                long upTime = runtimeBean.getUptime();
                if (upTime >= u.get() + 10000) {
                    u.set(upTime);
                    System.out.printf("Test Up Time    = %.3f (s)%n", upTime / 1000d);
                    System.out.printf("Heap Usage      = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.printf("None Heap Usage = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.println("=============================");
                }
                Thread.currentThread().sleep(10000l);
            } catch (InterruptedException ex) {
                Logger.getLogger(RedissonTestRunListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }).start();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 53 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project quasar by puniverse.

the class ProcessUtil method getCurrentPid.

public static int getCurrentPid() {
    try {
        RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
        jvmField.setAccessible(true);
        VMManagement vmManagement = (VMManagement) jvmField.get(runtimeMXBean);
        Method getProcessIdMethod = vmManagement.getClass().getDeclaredMethod("getProcessId");
        getProcessIdMethod.setAccessible(true);
        return (Integer) getProcessIdMethod.invoke(vmManagement);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Field(java.lang.reflect.Field) VMManagement(sun.management.VMManagement) RuntimeMXBean(java.lang.management.RuntimeMXBean) Method(java.lang.reflect.Method)

Example 54 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project dubbo by alibaba.

the class ConfigUtils method getPid.

public static int getPid() {
    if (PID < 0) {
        try {
            RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
            // format: "pid@hostname"  
            String name = runtime.getName();
            PID = Integer.parseInt(name.substring(0, name.indexOf('@')));
        } catch (Throwable e) {
            PID = 0;
        }
    }
    return PID;
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean)

Example 55 with RuntimeMXBean

use of java.lang.management.RuntimeMXBean in project mc-dev by Bukkit.

the class CrashReportJVMFlags method a.

public String a() {
    RuntimeMXBean runtimemxbean = ManagementFactory.getRuntimeMXBean();
    List list = runtimemxbean.getInputArguments();
    int i = 0;
    StringBuilder stringbuilder = new StringBuilder();
    Iterator iterator = list.iterator();
    while (iterator.hasNext()) {
        String s = (String) iterator.next();
        if (s.startsWith("-X")) {
            if (i++ > 0) {
                stringbuilder.append(" ");
            }
            stringbuilder.append(s);
        }
    }
    return String.format("%d total; %s", new Object[] { Integer.valueOf(i), stringbuilder.toString() });
}
Also used : Iterator(java.util.Iterator) List(java.util.List) RuntimeMXBean(java.lang.management.RuntimeMXBean)

Aggregations

RuntimeMXBean (java.lang.management.RuntimeMXBean)81 OperatingSystemMXBean (java.lang.management.OperatingSystemMXBean)13 MemoryMXBean (java.lang.management.MemoryMXBean)10 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)9 IOException (java.io.IOException)8 ThreadMXBean (java.lang.management.ThreadMXBean)7 MemoryUsage (java.lang.management.MemoryUsage)6 ArrayList (java.util.ArrayList)6 ClassLoadingMXBean (java.lang.management.ClassLoadingMXBean)5 Properties (java.util.Properties)5 InputStream (java.io.InputStream)4 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 Field (java.lang.reflect.Field)4 Method (java.lang.reflect.Method)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 BufferedReader (java.io.BufferedReader)3 File (java.io.File)3 InputStreamReader (java.io.InputStreamReader)3