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


Java OperatingSystemMXBean.getAvailableProcessors方法代码示例

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


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

示例1: getOsInfo

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public static void getOsInfo() {
    OperatingSystemMXBean osBean = ManagementFactory.getOperatingSystemMXBean();
    //os general info
    String osName = osBean.getName();
    String osVersion = osBean.getVersion();
    String osArch = osBean.getArch();

    //CPU
    int cores = osBean.getAvailableProcessors();
    String cpuName = System.getenv("PROCESSOR_IDENTIFIER");
    //only on *nix systems
    double loadAvg = osBean.getSystemLoadAverage();

    if (osBean instanceof com.sun.management.OperatingSystemMXBean) {
        getExtendedOsInfo((com.sun.management.OperatingSystemMXBean) osBean);
    }
}
 
开发者ID:games647,项目名称:Java-Snippets,代码行数:18,代码来源:EnvironmentInfo.java

示例2: Average

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@JMXBeanAttribute(name = "CPU: System Load Average (%)", description = "the recent cpu usage for the whole system. -1 if not available", sortValue = "f1")
public double getSystemCpuLoad() {
   switch (systemCpuLoadAvailable) {
   case 0:
      return -1;
   case 1:
      OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
      double load = operatingSystemMXBean.getSystemLoadAverage() * 100
            / operatingSystemMXBean.getAvailableProcessors();
      return load;

   case 2:
      return (double) retrieveLoadAttribute(SYSTEMATTRIBUTE) * 100;

   default:
      return -1;
   }
}
 
开发者ID:Wolfgang-Winter,项目名称:cibet,代码行数:19,代码来源:VMLoadControlJMXBean.java

示例3: logCPUInfo

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
static void logCPUInfo() {
    LogRecord log = new LogRecord(Level.FINEST, MESSAGE); // NOI18N
    OperatingSystemMXBean bean = ManagementFactory.getOperatingSystemMXBean();
    Object [] params = new Object[]{bean.getAvailableProcessors()};
    log.setParameters(params);
    Logger.getLogger(Installer.UI_PERFORMANCE_LOGGER_NAME).log(log);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:CPUInfo.java

示例4: check

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:LoadStatusChecker.java

示例5: check

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:13,代码来源:LoadStatusChecker.java

示例6: telnet

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
   public String telnet(Channel channel, String message) {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
   	double load;
   	try {
   	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
   	    load = (Double)method.invoke(operatingSystemMXBean, new Object[0]);
   	} catch (Throwable e) {
   	    load = -1;
   	}
   	int cpu = operatingSystemMXBean.getAvailableProcessors();
	return "load:[" + load + "] cpu:[" + cpu + "]";
}
 
开发者ID:tiglabs,项目名称:jsf-sdk,代码行数:14,代码来源:LoadTelnetHandler.java

示例7: check

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), "Load: " + load + " / CPU: " + cpu);
}
 
开发者ID:l1325169021,项目名称:github-test,代码行数:13,代码来源:LoadStatusChecker.java

示例8: getOSInfo

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/***
 * Get OS information.
 */
private static void getOSInfo(){
	
	OperatingSystemMXBean osbean = ManagementFactory.getOperatingSystemMXBean();
	osName = osbean.getName();
	osArch = osbean.getArch();
	osVersion = osbean.getVersion();
	cpuUsage = osbean.getSystemLoadAverage();
	availableProcessors = osbean.getAvailableProcessors();

}
 
开发者ID:ParkJinSang,项目名称:Jinseng-Server,代码行数:14,代码来源:ServerStatus.java

示例9: check

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public Status check() {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load;
	try {
	    Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage");
	    load = (Double)method.invoke(operatingSystemMXBean);
	} catch (Throwable e) {
	    load = -1;
	}
	int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN), (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
开发者ID:linux-china,项目名称:dubbo3,代码行数:13,代码来源:LoadStatusChecker.java

示例10: create

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public static OperatingSystemInfo create() {
    OperatingSystemInfo operatingSystemInfo = new OperatingSystemInfo();

    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();

    operatingSystemInfo.name = operatingSystemMXBean.getName();
    operatingSystemInfo.version = operatingSystemMXBean.getVersion();

    if (SystemUtils.IS_OS_LINUX) {
        operatingSystemInfo.distributionName = resolveLinuxDistributionName();
    }

    operatingSystemInfo.architecture = operatingSystemMXBean.getArch();
    operatingSystemInfo.numberOfLogicalProcessors = operatingSystemMXBean.getAvailableProcessors();

    if (com.sun.management.OperatingSystemMXBean.class.isAssignableFrom(operatingSystemMXBean.getClass())) {
        com.sun.management.OperatingSystemMXBean sunOsMxBean = com.sun.management.OperatingSystemMXBean.class.cast(operatingSystemMXBean);
        operatingSystemInfo.physicalMemorySizeInBytes = sunOsMxBean.getTotalPhysicalMemorySize();
        operatingSystemInfo.swapSpaceSizeInBytes = sunOsMxBean.getTotalSwapSpaceSize();
    }

    Map<String, Long> diskSpaceInBytesByRootPaths = new HashMap<>();
    for (File rootFile : File.listRoots()) {
        diskSpaceInBytesByRootPaths.put(rootFile.getAbsolutePath(), rootFile.getTotalSpace());
    }
    operatingSystemInfo.diskSpaceInBytesByRootPaths = diskSpaceInBytesByRootPaths;

    return operatingSystemInfo;
}
 
开发者ID:centro,项目名称:monitoring-center,代码行数:30,代码来源:OperatingSystemInfo.java

示例11: logCpuStats

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
/**
 * Log the CPU stats
 */
public static void logCpuStats() {
    OperatingSystemMXBean operatingSystemMXBean = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
    RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
    int availableProcessors = operatingSystemMXBean.getAvailableProcessors();
    long upTime = runtimeMXBean.getUptime();
    double loadAverage = operatingSystemMXBean.getSystemLoadAverage();
    log.info("Available processors: " + availableProcessors);
    log.info("JVM upTime (ms): " + upTime);
    log.info("CPU load average: " + loadAverage);
}
 
开发者ID:omerio,项目名称:ecarf,代码行数:14,代码来源:Utils.java

示例12: check

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public Status check() {
    OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
    double load;
    try {
        Method method = OperatingSystemMXBean.class.getMethod("getSystemLoadAverage", new Class<?>[0]);
        load = (Double) method.invoke(operatingSystemMXBean, new Object[0]);
    } catch (Throwable e) {
        load = -1;
    }
    int cpu = operatingSystemMXBean.getAvailableProcessors();
    return new Status(load < 0 ? Status.Level.UNKNOWN : (load < cpu ? Status.Level.OK : Status.Level.WARN),
                      (load < 0 ? "" : "load:" + load + ",") + "cpu:" + cpu);
}
 
开发者ID:MOBX,项目名称:Thor,代码行数:14,代码来源:LoadStatusChecker.java

示例13: sayHello

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
public String sayHello(final String queryString) {
    final OperatingSystemMXBean osmxbean = ManagementFactory.getOperatingSystemMXBean();
    final MemoryMXBean memxbean = ManagementFactory.getMemoryMXBean();
    final double load = osmxbean.getSystemLoadAverage() / osmxbean.getAvailableProcessors();
    final MemoryUsage mamUsage = memxbean.getHeapMemoryUsage();
    final long maxMem = mamUsage.getMax();
    final double usedmem = mamUsage.getUsed();
    return String.join(",", "Hello there ", queryString, ". My CPU load is ", Double.toString(load), "my heap mem usage is ", Double.toString(usedmem / ((maxMem >= 0) ? maxMem : mamUsage.getCommitted())));
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:11,代码来源:WebApiEJB.java

示例14: check

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
@Override
protected Result check() throws Exception {
	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	double load = operatingSystemMXBean.getSystemLoadAverage();
	int cpu = operatingSystemMXBean.getAvailableProcessors();
	if (load < cpu) {
		return Result.healthy();
	} else {
		return Result.unhealthy("load:%s,cpu:%s", load, cpu);
	}
	
}
 
开发者ID:cqyijifu,项目名称:watcher,代码行数:13,代码来源:SystemLoadHealthCheck.java

示例15: RemoteEvaluationWorker

import java.lang.management.OperatingSystemMXBean; //导入方法依赖的package包/类
public RemoteEvaluationWorker(String serverName, int port, String secret) throws UnknownHostException, IOException {
	this.serverName = serverName;
	this.port = port;
	this.secret = secret;

	setup();
	try {
		Thread.sleep(1000);
	} catch (InterruptedException e) {
		logger.error("Interrupted while initializing", e);
	}
	if (socket.isClosed())
		throw new RuntimeException("Socket was closed after connection setup");

	OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
	int numCPUs = operatingSystemMXBean.getAvailableProcessors();
	int queueSize = numCPUs * queueMultiplier;

	workQueue = new ArrayBlockingQueue<>(queueSize);
	resultQueue = new ArrayBlockingQueue<>(queueSize * 4);

	tpe = new ThreadPoolExecutor(numCPUs, numCPUs, 5, TimeUnit.MINUTES, workQueue);

	sendThread = new SendingThread();
	recvThread = new ReceivingThread();

	recvThread.start();
	sendThread.start();

}
 
开发者ID:kkoning,项目名称:SimpleGridExecutorService,代码行数:31,代码来源:RemoteEvaluationWorker.java


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