本文整理汇总了Java中java.lang.management.BufferPoolMXBean.getCount方法的典型用法代码示例。如果您正苦于以下问题:Java BufferPoolMXBean.getCount方法的具体用法?Java BufferPoolMXBean.getCount怎么用?Java BufferPoolMXBean.getCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.BufferPoolMXBean
的用法示例。
在下文中一共展示了BufferPoolMXBean.getCount方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: check
import java.lang.management.BufferPoolMXBean; //导入方法依赖的package包/类
static void check(List<BufferPoolMXBean> pools,
int minBufferCount,
long minTotalCapacity)
{
int bufferCount = 0;
long totalCap = 0;
long totalMem = 0;
for (BufferPoolMXBean pool: pools) {
bufferCount += pool.getCount();
totalCap += pool.getTotalCapacity();
totalMem += pool.getMemoryUsed();
}
if (bufferCount < minBufferCount)
throw new RuntimeException("Count less than expected");
if (totalMem < minTotalCapacity)
throw new RuntimeException("Memory usage less than expected");
if (totalCap < minTotalCapacity)
throw new RuntimeException("Total capacity less than expected");
}
示例2: BufferPoolMetricSet
import java.lang.management.BufferPoolMXBean; //导入方法依赖的package包/类
BufferPoolMetricSet() {
this.bufferPoolMXBeans = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
List<BufferPoolStatus> bufferPoolStatuses = new ArrayList<>();
Map<String, Metric> metricsByNames = new HashMap<>();
for (final BufferPoolMXBean bufferPoolMXBean : bufferPoolMXBeans) {
final String bufferPoolName = bufferPoolMXBean.getName();
final Gauge<Long> sizeGauge = new Gauge<Long>() {
@Override
public Long getValue() {
return bufferPoolMXBean.getCount();
}
};
metricsByNames.put(MetricNamingUtil.join(bufferPoolName, "size"), sizeGauge);
final Gauge<Long> totalCapacityInBytesGauge = new Gauge<Long>() {
@Override
public Long getValue() {
return bufferPoolMXBean.getTotalCapacity();
}
};
metricsByNames.put(MetricNamingUtil.join(bufferPoolName, "totalCapacityInBytes"), totalCapacityInBytesGauge);
final Gauge<Long> usedMemoryInBytesGauge;
if (bufferPoolMXBean.getMemoryUsed() >= 0) {
usedMemoryInBytesGauge = new Gauge<Long>() {
@Override
public Long getValue() {
return bufferPoolMXBean.getMemoryUsed();
}
};
metricsByNames.put(MetricNamingUtil.join(bufferPoolName, "usedMemoryInBytes"), usedMemoryInBytesGauge);
} else {
usedMemoryInBytesGauge = null;
}
bufferPoolStatuses.add(new BufferPoolStatus() {
@Override
public String getName() {
return bufferPoolName;
}
@Override
public Gauge<Long> getSizeGauge() {
return sizeGauge;
}
@Override
public Gauge<Long> getTotalCapacityInBytesGauge() {
return totalCapacityInBytesGauge;
}
@Override
public Gauge<Long> getUsedMemoryInBytesGauge() {
return usedMemoryInBytesGauge;
}
});
}
this.bufferPoolStatuses = bufferPoolStatuses;
this.metricsByNames = metricsByNames;
}