當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。