当前位置: 首页>>代码示例>>Java>>正文


Java RuntimeMXBean.getName方法代码示例

本文整理汇总了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();
}
 
开发者ID:vmantek,项目名称:chimera,代码行数:27,代码来源:SysDeployer.java

示例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);
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:26,代码来源:Substitutions.java

示例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;  
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:ConfigUtils.java

示例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;
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:10,代码来源:Bootstrap.java

示例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;
    }
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:10,代码来源:UtilAll.java

示例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;
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:45,代码来源:OSMXBean.java

示例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;
    }
}
 
开发者ID:y123456yz,项目名称:reading-and-annotate-rocketmq-3.4.6,代码行数:11,代码来源:UtilAll.java

示例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;
}
 
开发者ID:arodchen,项目名称:MaxSim,代码行数:10,代码来源:Test7194254.java

示例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;
}
 
开发者ID:tiglabs,项目名称:jsf-core,代码行数:14,代码来源:ScheduleServer.java


注:本文中的java.lang.management.RuntimeMXBean.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。