gpt4 book ai didi

java - eclipse java中三种不同方法增加JVM堆内存失败

转载 作者:行者123 更新时间:2023-12-01 21:09:09 25 4
gpt4 key购买 nike

我在我的系统上运行 32 位 JVM,并且使用 eclipse for java。我编写了一个程序来获取堆大小,如下所示:

public static void main(String[] args) {
long heapSize = Runtime.getRuntime().totalMemory();
System.out.println("current heap size: " + heapSize / 1000000f + " m");

long heapMaxSize = Runtime.getRuntime().maxMemory();
System.out.println("heapMaxsize: " + heapMaxSize / 1000000f + " m");

long heapFreeSize = Runtime.getRuntime().freeMemory();
System.out.println("heap free size: " + heapFreeSize / 1000000f + "m");

System.getProperty("sun.arch.data.model");
System.out.println("JVM is : " + System.getProperty("sun.arch.data.model"));
}

结果如下:

current heap size:  259.52255 m
heapMaxsize: 1037.9592 m
heap free size: 258.0899 m
JVM is : 32

现在我需要增加堆大小内存,因为我的大多数程序都提示堆大小内存。我尝试了 3 种方法来更改和增加堆大小,但失败了:

我还要提一下,我的电脑总内存为 8G,从任务管理器中可以看到其中 70% 以上一直在使用中。

方法一> Java配置> java > View >运行时参数>设置此值:-Xmx3g反馈:无

方法二>转到特定程序>运行配置>参数> -Xmx2048m反馈:

Error occurred during initialization of VM

Could not reserve enough space for 2097152KB object heap

方法 3> Eclipse> Windows> 首选项> Java> 安装的 JRE> 编辑> 在 VM 参数中,我键入:-Xms256M -Xmx2048M 反馈:

Error occurred during initialization of VM

Could not reserve enough space for 2097152KB object heap

问题:我不知道我还能做什么以及应该如何增加堆大小?

我解释的使用内存量超过 70% 是否总是对堆产生影响?

请帮助我!

最佳答案

您正在运行 32 位版本的 JVM。要访问更多内存,您需要切换到 64 位 JVM。

来自Oracle FAQ :

Why can't I get a larger heap with the 32-bit JVM?

The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64-bit operating systems running the 32-bit VM, the max heap size can be higher, approaching 4G on many Solaris systems.

关于java - eclipse java中三种不同方法增加JVM堆内存失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41561216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com