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];
}
}
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();
}
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);
}
}
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;
}
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() });
}
Aggregations