當前位置: 首頁>>代碼示例>>Java>>正文


Java RuntimeMXBean類代碼示例

本文整理匯總了Java中java.lang.management.RuntimeMXBean的典型用法代碼示例。如果您正苦於以下問題:Java RuntimeMXBean類的具體用法?Java RuntimeMXBean怎麽用?Java RuntimeMXBean使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RuntimeMXBean類屬於java.lang.management包,在下文中一共展示了RuntimeMXBean類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getHeapDumpPathOption

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
/**
 * Retrieves the value of the <code>HeapDumpPath</code> JVM option.
 * @return the value of the <code>HeapDumpPath</code> JVM option or <code>null</code> if the value has not been
 * specified.
 */
private static String getHeapDumpPathOption()
{
    RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
    List<String> inputArguments = runtimeMxBean.getInputArguments();
    String heapDumpPathOption = null;
    for (String argument : inputArguments)
    {
        if (argument.startsWith("-XX:HeapDumpPath="))
        {
            heapDumpPathOption = argument;
            // We do not break in case the option has been specified several times.
            // In general it seems that JVMs use the right-most argument as the winner.
        }
    }

    if (heapDumpPathOption == null)
        return null;

    return heapDumpPathOption.substring(17, heapDumpPathOption.length());
}
 
開發者ID:Netflix,項目名稱:sstable-adaptor,代碼行數:26,代碼來源:HeapUtils.java

示例2: handleStartupInfo

import java.lang.management.RuntimeMXBean; //導入依賴的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

示例3: isDebugged

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
private static synchronized boolean isDebugged() {
    if (debugMode == null) {
        debugMode = Boolean.FALSE;

        // check if we are debugged
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        List<String> args = runtime.getInputArguments();
        if (args.contains(X_DEBUG_ARG)) {
            debugMode = Boolean.TRUE;
        } else if (args.contains(JDWP_DEBUG_ARG)) {
            debugMode = Boolean.TRUE;
        } else {
            for (String arg : args) {
                if (arg.startsWith(JDWP_DEBUG_ARG_PREFIX)) {
                    debugMode = Boolean.TRUE;
                    break;
                }
            }
        }
    }
    return debugMode.booleanValue();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:23,代碼來源:InternalSampler.java

示例4: checkIfDebugged

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
private static boolean checkIfDebugged() {
    try {
        RuntimeMXBean runtime = ManagementFactory.getRuntimeMXBean();
        List<String> args = runtime.getInputArguments();
        for (String arg : args) {
            if ("-Xdebug".equals(arg)) { // NOI18N
                return true;                        
            } else if ("-agentlib:jdwp".equals(arg)) { // NOI18N
                // The idea of checking -agentlib:jdwp 
                // is taken from org.netbeans.modules.sampler.InternalSampler
                return true;
            } else if (arg.startsWith("-agentlib:jdwp=")) { // NOI18N
                return true;
            }
        }
    } catch (SecurityException ex) {                
    }
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:MiscUtils.java

示例5: testRunStarted

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
@Override
public void testRunStarted(Description description) throws Exception {
    super.testRunStarted(description);
    Runtime.getRuntime().addShutdownHook(new Thread(() -> {
        running.set(Boolean.FALSE);
    }));
    new Thread(() -> {
        final RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        final AtomicLong u = new AtomicLong(runtimeBean.getUptime());
        while (running.get()) {
            try {
                long upTime = runtimeBean.getUptime();
                if (upTime >= u.get() + 10000) {
                    u.set(upTime);
                    System.out.printf("Test Up Time    = %.3f (s)%n", upTime / 1000d);
                    System.out.printf("Heap Usage      = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.printf("None Heap Usage = %.3f (MB)%n", ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed() / 1024d / 1024d);
                    System.out.println("=============================");
                }
                Thread.currentThread().sleep(10000l);
            } catch (InterruptedException ex) {
                Logger.getLogger(RedissonTestRunListener.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }).start();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:27,代碼來源:RedissonTestRunListener.java

示例6: 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

示例7: refresh

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
@Override
public void refresh() {
    if(HostInfo.isTomcat()){
        webInfo = "view";
    }
    RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
    upTime = runtimeBean.getUptime();
    EnApp enApp = EnFactory.getEnApp();
    enApp.refresh();
    appid = nullToNA(EnFactory.getEnBase().getAppId());
    appName = nullToNA(enApp.getName());
    appChineseName = nullToNA(enApp.getChineseName());
    appOwner = nullToNA(enApp.getOwner());
    appOwnerEmail = nullToNA(enApp.getOwnerContact());
    appBackup = nullToNA(enApp.getBackup());
    appVersion = nullToNA(enApp.getVersion());
    buildTime = nullToNA(enApp.getBuildTime());
    getStatus();
}
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:20,代碼來源:AppInfo.java

示例8: getJvmStartupOptions

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
/**
 * Gets the system parameters and environment parameters that were passed to the JVM on startup.
 *
 * @return The options passed to the JVM on startup.
 */
public static String getJvmStartupOptions() {
	try {
		final RuntimeMXBean bean = ManagementFactory.getRuntimeMXBean();
		final StringBuilder bld = new StringBuilder();
		
		for (String s : bean.getInputArguments()) {
			bld.append(s).append(' ');
		}

		return bld.toString();
	}
	catch (Throwable t) {
		return UNKNOWN;
	}
}
 
開發者ID:huang-up,項目名稱:mycat-src-1.6.1-RELEASE,代碼行數:21,代碼來源:EnvironmentInformation.java

示例9: 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

示例10: addJvmArgsToSnooper

import java.lang.management.RuntimeMXBean; //導入依賴的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:Notoh,項目名稱:DecompiledMinecraft,代碼行數:17,代碼來源:PlayerUsageSnooper.java

示例11: getDirectMemorySize

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
public static long getDirectMemorySize() {
  RuntimeMXBean RuntimemxBean = ManagementFactory.getRuntimeMXBean();
  List<String> arguments = Lists.reverse(RuntimemxBean.getInputArguments());
  long multiplier = 1; //for the byte case.
  for (String s : arguments) {
    if (s.contains(MAX_DIRECT_MEMORY_PARAM)) {
      String memSize = s.toLowerCase(Locale.ENGLISH)
          .replace(MAX_DIRECT_MEMORY_PARAM.toLowerCase(Locale.ENGLISH), "").trim();

      if (memSize.contains("k")) {
        multiplier = 1024;
      } else if (memSize.contains("m")) {
        multiplier = 1048576;
      } else if (memSize.contains("g")) {
        multiplier = 1073741824;
      }
      memSize = memSize.replaceAll("[^\\d]", "");
      long retValue = Long.parseLong(memSize);
      return retValue * multiplier;
    }
  }
  return DEFAULT_SIZE;
}
 
開發者ID:moueimei,項目名稱:flume-release-1.7.0,代碼行數:24,代碼來源:DirectMemoryUtils.java

示例12: reportCPU

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
private Optional<Double> reportCPU(OperatingSystemMXBean operatingSystemMXBean, RuntimeMXBean runtimeMXBean) {
    int availableProcessors = divideByNbCores ? operatingSystemMXBean.getAvailableProcessors() : 1;
    long upTime = runtimeMXBean.getUptime();
    long processCpuTime = operatingSystemMXBean.getProcessCpuTime();

    if (lastMeasures == null
            || lastMeasures.availableProcessors != availableProcessors
            || lastMeasures.processCpuTime < 0) {
        lastMeasures = new Measures(availableProcessors, upTime, processCpuTime);
        return Optional.empty();
    }

    long elapsedCpu = processCpuTime - lastMeasures.processCpuTime;
    long elapsedTime = upTime - lastMeasures.upTime;
    lastMeasures = new Measures(availableProcessors, upTime, processCpuTime);

    return Optional.of(Math.min(99D, elapsedCpu / (elapsedTime * 10000D * availableProcessors)));
}
 
開發者ID:jotak,項目名稱:hawkular-java-toolbox,代碼行數:19,代碼來源:CPUMonitoring.java

示例13: getLastModifiedTime

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
@Override
protected long getLastModifiedTime() {
    try {
        URL url = ResourceUtils.getResourceAsUrl(resource);
        if ("file".equals(url.getProtocol())) {
            File file = new File(url.getFile());
            return file.lastModified();
        }
    } catch (IOException ex) {
        // ignore
    }
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    long startTime = runtimeMXBean.getStartTime();
    // Container start time (browsers are only accurate to the second)
    return startTime - (startTime % 1000);
}
 
開發者ID:devefx,項目名稱:validator-web,代碼行數:17,代碼來源:FileJavaScriptHandler.java

示例14: logSystemInfo

import java.lang.management.RuntimeMXBean; //導入依賴的package包/類
public static void logSystemInfo() {
    try {
        OperatingSystemMXBean operatingSystemBean = ManagementFactory.getOperatingSystemMXBean();
        Log.info("Operating system"
                + " name: " + operatingSystemBean.getName()
                + " version: " + operatingSystemBean.getVersion()
                + " architecture: " + operatingSystemBean.getArch());

        RuntimeMXBean runtimeBean = ManagementFactory.getRuntimeMXBean();
        Log.info("Java runtime"
                + " name: " + runtimeBean.getVmName()
                + " vendor: " + runtimeBean.getVmVendor()
                + " version: " + runtimeBean.getVmVersion());

        MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
        Log.info("Memory limit"
                + " heap: " + memoryBean.getHeapMemoryUsage().getMax() / (1024 * 1024) + "mb"
                + " non-heap: " + memoryBean.getNonHeapMemoryUsage().getMax() / (1024 * 1024) + "mb");

        Log.info("Character encoding: "
                + System.getProperty("file.encoding") + " charset: " + Charset.defaultCharset());

    } catch (Exception error) {
        Log.warning("Failed to get system info");
    }
}
 
開發者ID:bamartinezd,項目名稱:traccar-service,代碼行數:27,代碼來源:Log.java

示例15: getProcessId

import java.lang.management.RuntimeMXBean; //導入依賴的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


注:本文中的java.lang.management.RuntimeMXBean類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。