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