jconsole无法节省非主内存的使用

发布于 2025-02-11 18:44:24 字数 1012 浏览 1 评论 0原文

我使用bytebuffer.alocatedirect(int)在非Heap空间上分配直接缓冲区(100m),直到java.lang.outofmemoryerror:直接缓冲器存储器 forress。

但是,当我使用jconsole监视非主内存的使用情况时,未显示直接缓冲器

import java.nio.ByteBuffer;
import java.util.LinkedList;

public class BufferTest {
    public static void main(String[] args) throws InterruptedException {
        LinkedList<ByteBuffer> ll = new LinkedList<ByteBuffer>();
        int i = 0;

        while (true) {
            ByteBuffer buffer = ByteBuffer.allocateDirect(100 * 1024 * 1024);
            while (buffer.hasRemaining()) {
                buffer.put((byte) 1);
            }
            ll.add(buffer);

            System.out.println(i++ + "\t" + buffer.isDirect() + "\t" + buffer.limit());
            Thread.sleep(1000);
        }
    }
}

I use ByteBuffer.allocateDirect(int) to allocate direct buffer(100M) on non-heap space until java.lang.OutOfMemoryError: Direct buffer memory error thrown.

But when I use jconsole to monitoring the non-heap memory usage, no direct buffer used memory is shown.

import java.nio.ByteBuffer;
import java.util.LinkedList;

public class BufferTest {
    public static void main(String[] args) throws InterruptedException {
        LinkedList<ByteBuffer> ll = new LinkedList<ByteBuffer>();
        int i = 0;

        while (true) {
            ByteBuffer buffer = ByteBuffer.allocateDirect(100 * 1024 * 1024);
            while (buffer.hasRemaining()) {
                buffer.put((byte) 1);
            }
            ll.add(buffer);

            System.out.println(i++ + "\t" + buffer.isDirect() + "\t" + buffer.limit());
            Thread.sleep(1000);
        }
    }
}

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文