本文整理汇总了Java中java.lang.management.RuntimeMXBean.getName方法的典型用法代码示例。如果您正苦于以下问题:Java RuntimeMXBean.getName方法的具体用法?Java RuntimeMXBean.getName怎么用?Java RuntimeMXBean.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.RuntimeMXBean
的用法示例。
在下文中一共展示了RuntimeMXBean.getName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
public void start() throws Exception
{
ConfigurableEnvironment ce = (ConfigurableEnvironment) applicationContext.getEnvironment();
RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
String jvmName = runtimeBean.getName();
long pid = Long.valueOf(jvmName.split("@")[0]);
final File tmpDir = new File(".", ".tmp_" + pid);
if (tmpDir.exists())
{
deleteRecursive(tmpDir);
}
//noinspection ResultOfMethodCallIgnored
tmpDir.mkdir();
Runtime.getRuntime().addShutdownHook(new Thread(this::stop));
baseDir = tmpDir.getAbsolutePath();
PropertyResolver resolver = new SpringPropertyResolver(ce);
resolver.initialize();
deployer = ResourceDeployer.newInstance(resolver, tmpDir);
deployer.installRuntimeResources();
deployer.startConfigMonitoring();
}
示例2: Substitutions
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
public Substitutions(Date currentDate, int sequence)
{
RuntimeMXBean runtimeMx = ManagementFactory.getRuntimeMXBean();
String vmName = runtimeMx.getName();
pid = (vmName.indexOf('@') > 0)
? vmName.substring(0, vmName.indexOf('@'))
: "unknown";
hostname = (vmName.indexOf('@') > 0)
? vmName.substring(vmName.indexOf('@') + 1, vmName.length())
: "unknown";
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
date = dateFormat.format(currentDate);
SimpleDateFormat timestampFormat = new SimpleDateFormat("yyyyMMddHHmmss");
timestampFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
timestamp = timestampFormat.format(currentDate);
hourlyTimestamp = timestamp.substring(0, 10) + "0000"; // yeah, it's a hack
startupTimestamp = timestampFormat.format(new Date(runtimeMx.getStartTime()));
this.sequence = String.valueOf(sequence);
}
示例3: getPid
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
public static int getPid() {
if (PID < 0) {
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName(); // format: "[email protected]"
PID = Integer.parseInt(name.substring(0, name.indexOf('@')));
} catch (Throwable e) {
PID = 0;
}
}
return PID;
}
示例4: getPid
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
private static Integer getPid() {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName();
try {
return Integer.parseInt(name.substring(0, name.indexOf('@')));
} catch (Exception e) {
}
return -1;
}
示例5: getPid
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
public static int getPid() {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName(); // format: "[email protected]"
try {
return Integer.parseInt(name.substring(0, name.indexOf('@')));
} catch (Exception e) {
return -1;
}
}
示例6: getOpenFileDescriptorCount
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
/**
* Get the number of opened filed descriptor for the runtime jvm.
* If sun java, it will use the com.sun.management interfaces.
* Otherwise, this methods implements it (linux only).
* @return number of open file descriptors for the jvm
*/
public long getOpenFileDescriptorCount()
{
Long ofdc;
if (!ibmvendor) {
ofdc = getOSUnixMXBeanMethod("getOpenFileDescriptorCount");
return (ofdc != null ? ofdc.longValue () : -1);
}
try {
//need to get the PID number of the process first
RuntimeMXBean rtmbean = ManagementFactory.getRuntimeMXBean();
String rtname = rtmbean.getName();
String[] pidhost = rtname.split("@");
//using linux bash commands to retrieve info
Process p = Runtime.getRuntime().exec(
new String[] { "bash", "-c",
"ls /proc/" + pidhost[0] + "/fdinfo | wc -l" });
InputStream in = p.getInputStream();
BufferedReader output = new BufferedReader(
new InputStreamReader(in));
try {
String openFileDesCount;
if ((openFileDesCount = output.readLine()) != null) {
return Long.parseLong(openFileDesCount);
}
} finally {
if (output != null) {
output.close();
}
}
} catch (IOException ie) {
LOG.warn("Not able to get the number of open file descriptors", ie);
}
return -1;
}
示例7: getPid
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
public static int getPid() {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName(); // format: "[email protected]"
try {
return Integer.parseInt(name.substring(0, name.indexOf('@')));
}
catch (Exception e) {
return -1;
}
}
示例8: getPid
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
static String getPid() {
RuntimeMXBean runtimebean = ManagementFactory.getRuntimeMXBean();
String vmname = runtimebean.getName();
int i = vmname.indexOf('@');
if (i != -1) {
vmname = vmname.substring(0, i);
}
return vmname;
}
示例9: getPid
import java.lang.management.RuntimeMXBean; //导入方法依赖的package包/类
public static int getPid() {
int PID = -1;
if (PID < 0) {
try {
RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
String name = runtime.getName(); // format: "[email protected]"
PID = Integer.parseInt(name.substring(0, name.indexOf('@')));
} catch (Throwable e) {
PID = 0;
}
}
return PID;
}