use of java.lang.management.RuntimeMXBean in project syncany by syncany.
the class PidFileUtil method getProcessPidImpl2.
/**
* Uses the private method <tt>VMManagement.getProcessId()</tt> of Sun's <tt>sun.management.VMManagement</tt>
* class to determine the PID (using reflection to make the relevant fields visible).
*
* @see http://stackoverflow.com/a/12066696/1440785
*/
private static int getProcessPidImpl2() throws Exception {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
Field jvmField = runtimeMXBean.getClass().getDeclaredField("jvm");
jvmField.setAccessible(true);
// The returned object is of the type 'sun.management.VMManagement', but since we
// don't need the exact type here and we don't want to reference it in the
// imports, we'll just hope it's there.
Object vmManagement = jvmField.get(runtimeMXBean);
Method getProcessIdMethod = vmManagement.getClass().getDeclaredMethod("getProcessId");
getProcessIdMethod.setAccessible(true);
int processPid = (Integer) getProcessIdMethod.invoke(vmManagement);
logger.log(Level.INFO, "Java Process PID is " + processPid);
return processPid;
}
use of java.lang.management.RuntimeMXBean in project jPOS by jpos.
the class SystemMonitor method generateFrozenDump.
private String generateFrozenDump(String indent) {
RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
ThreadMXBean mxBean = ManagementFactory.getThreadMXBean();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream p = new PrintStream(baos);
String newIndent = indent + " ";
Runtime r = getRuntimeInstance();
ZoneId zi = ZoneId.systemDefault();
Instant instant = Instant.now();
File cwd = new File(".");
String freeSpace = ISOUtil.readableFileSize(cwd.getFreeSpace());
String usableSpace = ISOUtil.readableFileSize(cwd.getUsableSpace());
p.printf("%s OS: %s (%s)%n", indent, System.getProperty("os.name"), System.getProperty("os.version"));
int maxKeyLength = 0;
try {
maxKeyLength = Cipher.getMaxAllowedKeyLength("AES");
} catch (NoSuchAlgorithmException ignored) {
}
p.printf("%s Java: %s (%s) AES-%s%n", indent, System.getProperty("java.version"), System.getProperty("java.vendor"), maxKeyLength == Integer.MAX_VALUE ? "secure" : Integer.toString(maxKeyLength));
p.printf("%s process name: %s%n", indent, runtimeMXBean.getName());
p.printf("%s host: %s%n", indent, getLocalHost());
p.printf("%s cwd: %s%n", indent, System.getProperty("user.dir"));
p.printf("%s free space: %s%n", indent, freeSpace);
if (!freeSpace.equals(usableSpace))
p.printf("%s usable space: %s%n", indent, usableSpace);
p.printf("%s version: %s (%s)%n", indent, Q2.getVersion(), getRevision());
p.printf("%s instance: %s%n", indent, getInstanceIdAsString());
p.printf("%s uptime: %s (%f)%n", indent, ISOUtil.millisToString(getServerUptimeAsMillisecond()), loadAverage());
p.printf("%s processors: %d%n", indent, r.availableProcessors());
p.printf("%s drift : %d%n", indent, delay);
p.printf("%smemory(t/u/f): %d/%d/%d%n", indent, r.totalMemory() / MB, (r.totalMemory() - r.freeMemory()) / MB, r.freeMemory() / MB);
p.printf("%s encoding: %s%n", indent, Charset.defaultCharset());
p.printf("%s timezone: %s (%s) %s%n", indent, zi, zi.getDisplayName(TextStyle.FULL, Locale.getDefault()), zi.getRules().getOffset(instant).toString());
p.printf("%swatch service: %s%n", indent, getServer().getWatchServiceClassname());
List<ZoneOffsetTransitionRule> l = zi.getRules().getTransitionRules();
for (ZoneOffsetTransitionRule tr : l) {
p.printf("%s rule: %s%n", indent, tr.toString());
}
ZoneOffsetTransition tran = zi.getRules().nextTransition(instant);
if (tran != null) {
Instant in = tran.getInstant();
p.printf("%s transition: %s (%s)%n", indent, in, in.atZone(zi));
}
p.printf("%s clock: %d %s%n", indent, System.currentTimeMillis() / 1000L, instant);
if (hasSecurityManager())
p.printf("%s sec-manager: %s%n", indent, getSecurityManager());
p.printf("%s thread count: %d%n", indent, mxBean.getThreadCount());
p.printf("%s peak threads: %d%n", indent, mxBean.getPeakThreadCount());
p.printf("%s user threads: %d%n", indent, Thread.activeCount());
showThreadGroup(Thread.currentThread().getThreadGroup(), p, newIndent);
NameRegistrar.getInstance().dump(p, indent, detailRequired);
for (String s : scripts) {
p.printf("%s%s:%n", indent, s);
exec(s, p, newIndent);
}
return baos.toString();
}
use of java.lang.management.RuntimeMXBean in project suite by stupidsing.
the class FileUtil method getPid.
public static int getPid() {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
return Rethrow.ex(() -> {
Field jvm = runtime.getClass().getDeclaredField("jvm");
jvm.setAccessible(true);
Object vmm = jvm.get(runtime);
Method method = vmm.getClass().getDeclaredMethod("getProcessId");
method.setAccessible(true);
return (Integer) method.invoke(jvm.get(runtime));
});
}
use of java.lang.management.RuntimeMXBean in project Payara by payara.
the class PhoneHomeTask method getUptime.
private String getUptime() {
RuntimeMXBean mxbean = ManagementFactory.getRuntimeMXBean();
long totalTime_ms = -1;
if (mxbean != null)
totalTime_ms = mxbean.getUptime();
if (totalTime_ms <= 0 && env != null) {
StartupContext ctx = env.getStartupContext();
if (ctx != null) {
long start = ctx.getCreationTime();
totalTime_ms = System.currentTimeMillis() - start;
}
}
return Long.toString(totalTime_ms);
}
use of java.lang.management.RuntimeMXBean in project Payara by payara.
the class ThreadMonitor method getTitle.
private String getTitle() throws Exception {
final RuntimeMXBean rt = ManagementFactory.newPlatformMXBeanProxy(mbsc, ManagementFactory.RUNTIME_MXBEAN_NAME, RuntimeMXBean.class);
final String vmname = rt.getVmName();
final String vmversion = rt.getVmVersion();
final String vmvendor = rt.getVmVendor();
final String title = sm.getString("td.title", vmname, vmversion, vmvendor);
return (title);
}
Aggregations