本文整理汇总了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();
}