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


Java ManagementFactory.getRuntimeMXBean方法代码示例

本文整理汇总了Java中java.lang.management.ManagementFactory.getRuntimeMXBean方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getRuntimeMXBean方法的具体用法?Java ManagementFactory.getRuntimeMXBean怎么用?Java ManagementFactory.getRuntimeMXBean使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.lang.management.ManagementFactory的用法示例。


在下文中一共展示了ManagementFactory.getRuntimeMXBean方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleStartupInfo

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private boolean handleStartupInfo(@NotNull List<String> args) {
  if (args.size() > 0 && "startup-info".equals(args.get(0))) {
    String jvmLocation = API.getJvmLocation();
    infoln("%s", jvmLocation);
    RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
    List<String> jvmArgs = bean.getInputArguments();

    for (String jvmArg : jvmArgs) {
      infoln(jvmArg);
    }
    infoln("-classpath " + System.getProperty("java.class.path"));
    // print the non-JVM command line arguments
    // print name of the main class with its arguments, like org.ClassName param1 param2
    infoln(System.getProperty("sun.java.command"));
    return true;
  }
  return false;
}
 
开发者ID:jomof,项目名称:cdep,代码行数:19,代码来源:CDep.java

示例2: getProcessCpuUtilization

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * obtain current process cpu utilization if jdk version is 1.6 by-hongqiangwei
 */
@SuppressWarnings("restriction")
public static double getProcessCpuUtilization() {

    com.sun.management.OperatingSystemMXBean osMBean = (com.sun.management.OperatingSystemMXBean) ManagementFactory
            .getOperatingSystemMXBean();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();

    long processCpuTime1 = osMBean.getProcessCpuTime();
    long runtime1 = runtimeMXBean.getUptime();

    ThreadHelper.suspend(50);

    long processCpuTime2 = osMBean.getProcessCpuTime();
    long runtime2 = runtimeMXBean.getUptime();

    long deltaProcessTime = processCpuTime2 - processCpuTime1;
    long deltaRunTime = (runtime2 - runtime1) * 1000000L;
    int cpuNumber = Runtime.getRuntime().availableProcessors();
    double cpuUtilization = (double) deltaProcessTime / (deltaRunTime * cpuNumber);

    return cpuUtilization;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:26,代码来源:JVMToolHelper.java

示例3: addJvmArgsToSnooper

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void addJvmArgsToSnooper()
{
    RuntimeMXBean runtimemxbean = ManagementFactory.getRuntimeMXBean();
    List<String> list = runtimemxbean.getInputArguments();
    int i = 0;

    for (String s : list)
    {
        if (s.startsWith("-X"))
        {
            this.addClientStat("jvm_arg[" + i++ + "]", s);
        }
    }

    this.addClientStat("jvm_args", Integer.valueOf(i));
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:17,代码来源:PlayerUsageSnooper.java

示例4: getProcessId

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static Integer getProcessId() {
    try {
        // Get the current process id using a reflection hack
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        Field jvm = runtime.getClass().getDeclaredField("jvm");
        jvm.setAccessible(true);

        VMManagement mgmt = (sun.management.VMManagement) jvm.get(runtime);
        Method pid_method = mgmt.getClass().getDeclaredMethod("getProcessId");
        pid_method.setAccessible(true);
        Integer pid = (Integer) pid_method.invoke(mgmt);
        return pid;
    } catch(Exception ex) {
        return null;
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:JdpController.java

示例5: getHeapDump

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
static File getHeapDump() {
    String heapDumpPath = null;
    RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
    List<String> lst = RuntimemxBean.getInputArguments();
    for (String arg : lst) {
        if (arg.contains("XX:HeapDumpPath")){
            int index = arg.indexOf('=');
            heapDumpPath = arg.substring(index+1);
        }
    }

    if (heapDumpPath == null){
        LOG.info("XX:HeapDumpPath parametter not specified");
        return null;
    }
    File heapDumpFile = new File(heapDumpPath);
    if (heapDumpFile.exists() && heapDumpFile.canRead() && heapDumpFile.length() > 0) {
        return heapDumpFile;
    }
    LOG.log(Level.INFO, "heap dump was not created at {0}", heapDumpPath);
    LOG.log(Level.INFO, "heapdump file: exists():{0}, canRead():{1}, length:{2}",new Object[] 
            {heapDumpFile.exists(), heapDumpFile.canRead(), heapDumpFile.length()});
    // no heap dump file found - this can happen in case of OOME: unable to create new native thread
    // try to create heap dump 
    dumpHeap(heapDumpFile.getAbsolutePath());
    if (heapDumpFile.exists() && heapDumpFile.canRead() && heapDumpFile.length() > 0) {
        return heapDumpFile;
    }        
    LOG.log(Level.INFO, "heap dump failed for {0}", heapDumpPath);
    return null;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:32,代码来源:Installer.java

示例6: SabotConfig

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@VisibleForTesting
public SabotConfig(Config config, boolean enableServerConfigs) {
  super(config);
  logger.debug("Setting up SabotConfig object.");
  logger.trace("Given Config object is:\n{}",
               config.root().render(ConfigRenderOptions.defaults()));
  RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
  this.startupArguments = ImmutableList.copyOf(bean.getInputArguments());
  logger.debug("SabotConfig object initialized.");
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:SabotConfig.java

示例7: telnet

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
   public String telnet(Channel channel, String message) {
	StringBuilder sb = new StringBuilder();
	//内存使用情况
       MemoryMXBean mmxb = ManagementFactory.getMemoryMXBean();
       long max = mmxb.getHeapMemoryUsage().getMax();
       long used = mmxb.getHeapMemoryUsage().getUsed();
       long init = mmxb.getHeapMemoryUsage().getInit();
       long commit = mmxb.getHeapMemoryUsage().getCommitted();
       sb.append("********Memory status******************").append(line);
       sb.append("Max JVM Heap Memory:").append(max / 1024 / 1024).append("M").append(line)
               .append("Used Heap Memory:").append(used / 1024 / 1024).append("M").append(line)
               .append("Init Heap Memory:").append(init / 1024 / 1024).append("M").append(line)
               .append("Commited Heap Memory:").append(commit/1024/1024).append("M").append(line);
       
       sb.append("********Thread status********************").append(line);
       //线程数
       ThreadMXBean txmb = ManagementFactory.getThreadMXBean();
       sb.append("Peak thread count:").append(txmb.getPeakThreadCount()).append("").append(line)
               .append("Thread count:").append(txmb.getThreadCount()).append("").append(line);

       sb.append("********Runtime status******************").append(line);
       //启动入口参数
       RuntimeMXBean rmxb = ManagementFactory.getRuntimeMXBean();
       sb.append("InputArguments:[");
       for(String ia : rmxb.getInputArguments()){
       	sb.append(ia).append(",");
       }
       sb.deleteCharAt(sb.length()-1).append("]").append(line);
       sb.append("JVM start time:").append(DateUtils.dateToStr(new Date(rmxb.getStartTime()))).append(line);
       
       return sb.toString();
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:34,代码来源:JVMStatusTelnetHandler.java

示例8: getPid

import java.lang.management.ManagementFactory; //导入方法依赖的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

示例9: getPid

import java.lang.management.ManagementFactory; //导入方法依赖的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

示例10: getSystemStartTime

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public long getSystemStartTime() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    return rb.getStartTime();
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:6,代码来源:Controller.java

示例11: getRuntimeMXBean

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
static RuntimeMXBean getRuntimeMXBean() {
    return ManagementFactory.getRuntimeMXBean();
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:JvmRuntimeImpl.java

示例12: getUptime

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public Long getUptime() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    return rb.getUptime();
}
 
开发者ID:shlee89,项目名称:athena,代码行数:5,代码来源:Controller.java

示例13: getDuration

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * @return How long the service has been running.
 */
public static Duration getDuration() {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    return Duration.millis(runtimeMXBean.getUptime());
}
 
开发者ID:Azure,项目名称:pcs-storage-adapter-java,代码行数:8,代码来源:Uptime.java

示例14: getStart

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
 * @return When the service started.
 */
public static DateTime getStart() {
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    return new DateTime(runtimeMXBean.getStartTime()).toDateTime(DateTimeZone.UTC);
}
 
开发者ID:Azure,项目名称:device-telemetry-java,代码行数:8,代码来源:Uptime.java

示例15: runTest

import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static void runTest() throws Exception {
    RuntimeMXBean mbean = ManagementFactory.getRuntimeMXBean();

    // Print all system properties
    Map<String,String> props = mbean.getSystemProperties();
    printProperties(props);

    // Add new system properties
    System.setProperty(KEY1, VALUE1);
    System.setProperty(KEY2, VALUE2);

    Map<String,String> props1 = mbean.getSystemProperties();
    String value1 = props1.get(KEY1);
    if (value1 == null || !value1.equals(VALUE1)) {
        throw new RuntimeException(KEY1 + " property found" +
             " with value = " + value1 +
             " but expected to be " + VALUE1);
    }

    String value2 = props1.get(KEY2);
    if (value2 == null || !value2.equals(VALUE2)) {
        throw new RuntimeException(KEY2 + " property found" +
             " with value = " + value2 +
             " but expected to be " + VALUE2);
    }

    String value3 = props1.get(KEY3);
    if (value3 != null) {
        throw new RuntimeException(KEY3 + " property found" +
             " but should not exist" );
    }

    // Add new system properties but are not Strings
    Properties sp = System.getProperties();
    sp.put(KEY3, VALUE3);
    sp.put(KEY4, VALUE4);

    Map<String,String> props2 = mbean.getSystemProperties();
    // expect the system properties returned should be
    // same as the one before adding KEY3 and KEY4
    if (!props1.equals(props2)) {
        throw new RuntimeException("Two copies of system properties " +
            "are expected to be equal");
    }

    System.out.println("Test passed.");
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:48,代码来源:GetSystemProperties.java


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