com.hibegin.common.util.Pid Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of simplewebserver Show documentation
Show all versions of simplewebserver Show documentation
Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project.
Can quickly run embedded, Android devices
package com.hibegin.common.util;
import java.lang.reflect.Method;
import java.util.logging.Logger;
public class Pid {
public static final Logger LOGGER = LoggerUtil.getLogger(Pid.class);
public static long get() {
try {
//兼容java7
if (Class.forName("java.lang.management.ManagementFactory") != null) {
Object runtimeMXBean = Class.forName("java.lang.management.ManagementFactory").getMethod("getRuntimeMXBean").invoke(null);
Method method = runtimeMXBean.getClass().getMethod("getName");
method.setAccessible(true);
return Long.parseLong(((String) method.invoke(runtimeMXBean)).split("@")[0]);
}
} catch (Exception e) {
LOGGER.warning("get pid error " + e.getMessage());
}
return -1;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy