查找Java可以使用多少直接缓冲存储器? [英] Looking up how much direct buffer memory is available to Java?

查看:60
本文介绍了查找Java可以使用多少直接缓冲存储器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查找 http://bugs.sun.com/bugdatabase/view_bug的评估者.吗?bug_id = 4879883 提到过,Java在普通Java堆之外维护这些缓冲区.

How can one look up how much direct memory is currently allocated (and may be allocated) by Java? As the evaluator of http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4879883 mentions, Java maintains these buffers outside the normal Java heap.

推荐答案

可能还有其他方法可以使用本机代码(或配置文件等)完成此操作,但类似的方法可能在Java中起作用:

There are probably other ways to do this with native code (or profiling, etc.), but something like this might work in Java:

Class c = java.nio.Bits.class;
Field maxMemory = c.getDeclaredField("maxMemory");
maxMemory.setAccessible(true);
Field reservedMemory = c.getDeclaredField("reservedMemory");
reservedMemory.setAccessible(true);
synchronized (c) {
    Long maxMemoryValue = (Long)maxMemory.get(null);
    Long reservedMemoryValue = (Long)reservedMemory.get(null);
}

这篇关于查找Java可以使用多少直接缓冲存储器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆