本文整理匯總了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);
}
}
示例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;
}
}
示例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);
}
示例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);
}
示例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);
}
示例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 + "]";
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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())));
}
示例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);
}
}
示例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();
}