本文整理汇总了Java中java.lang.management.ManagementFactory.getMemoryPoolMXBeans方法的典型用法代码示例。如果您正苦于以下问题:Java ManagementFactory.getMemoryPoolMXBeans方法的具体用法?Java ManagementFactory.getMemoryPoolMXBeans怎么用?Java ManagementFactory.getMemoryPoolMXBeans使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.management.ManagementFactory
的用法示例。
在下文中一共展示了ManagementFactory.getMemoryPoolMXBeans方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
@Override
public void run() {
List<GarbageCollectorMXBean> garbageCollectorMXBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollectorMXBean garbageCollectorMXBean = CollectionUtils.findFirst(garbageCollectorMXBeans, new Spec<GarbageCollectorMXBean>() {
@Override
public boolean isSatisfiedBy(GarbageCollectorMXBean mbean) {
return mbean.getName().equals(garbageCollector);
}
});
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
String pool = memoryPoolMXBean.getName();
if (memoryPools.contains(pool)) {
GarbageCollectionEvent event = new GarbageCollectionEvent(System.currentTimeMillis(), memoryPoolMXBean.getCollectionUsage(), garbageCollectorMXBean.getCollectionCount());
events.get(pool).slideAndInsert(event);
}
}
}
示例2: getAllMemoryPoolNames
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
* Returns the names of all available memory pools as a single string.
*/
private static String getAllMemoryPoolNames() {
StringBuilder builder = new StringBuilder("[");
for (MemoryPoolMXBean memoryPoolBean : ManagementFactory.getMemoryPoolMXBeans()) {
builder.append("(Name=").append(memoryPoolBean.getName()).append(";Type=")
.append(memoryPoolBean.getType()).append(";UsageThresholdSupported=")
.append(memoryPoolBean.isUsageThresholdSupported()).append("), ");
}
if (builder.length() > 1) {
builder.setLength(builder.length() - 2);
}
builder.append("]");
return builder.toString();
}
示例3: main
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
boolean verified = false;
for (MemoryPoolMXBean i : pools) {
if ((i.getUsage().getMax() >= TWO_G)
&& i.isUsageThresholdSupported()) {
i.setUsageThreshold(TWO_G);
if(i.getUsageThreshold() != TWO_G)
throw new RuntimeException("Usage threshold for"
+ " pool '" + i.getName() + "' is " + i.getUsageThreshold()
+ " and not equal to 2GB");
verified = true;
}
}
System.out.println("Ability to use big heap thresholds has "
+ (verified ? "" : "NOT ") + "been verified");
}
示例4: setMemThreshold
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void setMemThreshold()
{
m_bMaxPermanentHeap_MoSet = false;
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
if(p.getType().compareTo(MemoryType.HEAP) == 0)
{
String cs = p.getName();
if(cs.equalsIgnoreCase("Tenured gen"))
{
long l = 1024L * 1024L * (long)m_nMaxPermanentHeap_Mo;
p.setUsageThreshold(l);
m_tenuredPool = p;
}
}
}
}
示例5: getUsage
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
* Get MemoryUsage from MemoryPoolMXBean which name matches passed string.
*
* @param name
* @return MemoryUsage
*/
private static MemoryUsage getUsage(String name){
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
if (pool.getName().matches(name)) {
return pool.getUsage();
}
}
return null;
}
示例6: reportMemoryPool
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private void reportMemoryPool() {
for (final MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
log.info("Memory Pool {} - type=\"{}\" memory-manager=\"{}\"", pool.getName(), pool.getType(), Joiner.on(',').join(pool.getMemoryManagerNames()));
log.info("Memory Pool {} - Usage {}", pool.getName(), pool.getUsage());
log.info("Memory Pool {} - Collection Usage {}", pool.getName(), pool.getCollectionUsage());
log.info("Memory Pool {} - Peak Usage {}", pool.getName(), pool.getPeakUsage());
log.info("Memory Pool {} - Type {}", pool.getName(), pool.getPeakUsage());
}
}
示例7: main
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static void main(String[] args) {
List<MemoryPoolMXBean> pmbList = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean mpmb : pmbList) {
System.out.println(mpmb.getName());
}
}
示例8: JvmGcMetrics
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public JvmGcMetrics(Iterable<Tag> tags) {
for (MemoryPoolMXBean mbean : ManagementFactory.getMemoryPoolMXBeans()) {
if (isYoungGenPool(mbean.getName()))
youngGenPoolName = mbean.getName();
if (isOldGenPool(mbean.getName()))
oldGenPoolName = mbean.getName();
}
this.tags = tags;
}
示例9: checkGcInfo
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static void checkGcInfo(String name, GcInfo info) throws Exception {
System.out.println("GC statistic for : " + name);
System.out.print("GC #" + info.getId());
System.out.print(" start:" + info.getStartTime());
System.out.print(" end:" + info.getEndTime());
System.out.println(" (" + info.getDuration() + "ms)");
Map usage = info.getMemoryUsageBeforeGc();
List pnames = new ArrayList();
for (Iterator iter = usage.entrySet().iterator(); iter.hasNext(); ) {
Map.Entry entry = (Map.Entry) iter.next();
String poolname = (String) entry.getKey();
pnames.add(poolname);
MemoryUsage busage = (MemoryUsage) entry.getValue();
MemoryUsage ausage = (MemoryUsage) info.getMemoryUsageAfterGc().get(poolname);
if (ausage == null) {
throw new RuntimeException("After Gc Memory does not exist" +
" for " + poolname);
}
System.out.println("Usage for pool " + poolname);
System.out.println(" Before GC: " + busage);
System.out.println(" After GC: " + ausage);
}
// check if memory usage for all memory pools are returned
List pools = ManagementFactory.getMemoryPoolMXBeans();
for (Iterator iter = pools.iterator(); iter.hasNext(); ) {
MemoryPoolMXBean p = (MemoryPoolMXBean) iter.next();
if (!pnames.contains(p.getName())) {
throw new RuntimeException("GcInfo does not contain " +
"memory usage for pool " + p.getName());
}
}
}
示例10: findPool
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static MemoryPoolMXBean findPool(String poolName) {
for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
if (pool.getName().contains(poolName)) {
return pool;
}
}
return null;
}
示例11: getAllPoolNames
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
synchronized String[] getAllPoolNames() {
if (poolNames == null) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
poolNames = new String[pools.size()];
int i = 0;
for (MemoryPoolMXBean m : pools) {
poolNames[i++] = m.getName();
}
}
return poolNames;
}
示例12: printUsage
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
/**
* Выводит в stdout информацию о текущем состоянии различных разделов памяти.
*/
public static void printUsage(boolean heapOnly) {
for(MemoryPoolMXBean mBean: ManagementFactory.getMemoryPoolMXBeans()) {
if (!heapOnly || mBean.getType() == MemoryType.HEAP) {
printMemUsage(mBean.getName(), mBean.getUsage());
}
}
}
示例13: DumpMemories
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
DumpMemories()
{
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean p: pools)
{
System.out.println("Memory type="+p.getType()+" Memory usage="+p.getUsage());
}
}
示例14: getMemoryPool
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
private static MemoryPoolMXBean getMemoryPool(String name) {
List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
for (MemoryPoolMXBean pool : pools) {
if (pool.getName().equals(name)) {
return pool;
}
}
throw new RuntimeException("Expected to find a memory pool with name " + name);
}
示例15: jvmStats
import java.lang.management.ManagementFactory; //导入方法依赖的package包/类
public static JvmStats jvmStats() {
MemoryUsage memUsage = memoryMXBean.getHeapMemoryUsage();
long heapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long heapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
long heapMax = memUsage.getMax() < 0 ? 0 : memUsage.getMax();
memUsage = memoryMXBean.getNonHeapMemoryUsage();
long nonHeapUsed = memUsage.getUsed() < 0 ? 0 : memUsage.getUsed();
long nonHeapCommitted = memUsage.getCommitted() < 0 ? 0 : memUsage.getCommitted();
List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
List<MemoryPool> pools = new ArrayList<>();
for (MemoryPoolMXBean memoryPoolMXBean : memoryPoolMXBeans) {
try {
MemoryUsage usage = memoryPoolMXBean.getUsage();
MemoryUsage peakUsage = memoryPoolMXBean.getPeakUsage();
String name = GcNames.getByMemoryPoolName(memoryPoolMXBean.getName(), null);
if (name == null) { // if we can't resolve it, its not interesting.... (Per Gen, Code Cache)
continue;
}
pools.add(new MemoryPool(name,
usage.getUsed() < 0 ? 0 : usage.getUsed(),
usage.getMax() < 0 ? 0 : usage.getMax(),
peakUsage.getUsed() < 0 ? 0 : peakUsage.getUsed(),
peakUsage.getMax() < 0 ? 0 : peakUsage.getMax()
));
} catch (Exception ex) {
/* ignore some JVMs might barf here with:
* java.lang.InternalError: Memory Pool not found
* we just omit the pool in that case!*/
}
}
Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed, Collections.unmodifiableList(pools));
Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());
List<GarbageCollectorMXBean> gcMxBeans = ManagementFactory.getGarbageCollectorMXBeans();
GarbageCollector[] collectors = new GarbageCollector[gcMxBeans.size()];
for (int i = 0; i < collectors.length; i++) {
GarbageCollectorMXBean gcMxBean = gcMxBeans.get(i);
collectors[i] = new GarbageCollector(GcNames.getByGcName(gcMxBean.getName(), gcMxBean.getName()),
gcMxBean.getCollectionCount(), gcMxBean.getCollectionTime());
}
GarbageCollectors garbageCollectors = new GarbageCollectors(collectors);
List<BufferPool> bufferPoolsList = Collections.emptyList();
try {
List<BufferPoolMXBean> bufferPools = ManagementFactory.getPlatformMXBeans(BufferPoolMXBean.class);
bufferPoolsList = new ArrayList<>(bufferPools.size());
for (BufferPoolMXBean bufferPool : bufferPools) {
bufferPoolsList.add(new BufferPool(bufferPool.getName(), bufferPool.getCount(),
bufferPool.getTotalCapacity(), bufferPool.getMemoryUsed()));
}
} catch (Exception e) {
// buffer pools are not available
}
Classes classes = new Classes(classLoadingMXBean.getLoadedClassCount(), classLoadingMXBean.getTotalLoadedClassCount(),
classLoadingMXBean.getUnloadedClassCount());
return new JvmStats(System.currentTimeMillis(), runtimeMXBean.getUptime(), mem, threads,
garbageCollectors, bufferPoolsList, classes);
}