简体   繁体   English

java-将堆空间增加到最大限制

[英]java - increasing heap space to maximum limit

So I am using intellij and working on a program. 所以我正在使用intellij并正在开发一个程序。 I left my VM options empty and ran the program, it throws outofmemory:java heap space exception. 我将我的VM选项留空并运行了程序,它抛出了outofmemory:java heap space异常。

So I decided to ramp up the heap space, by adding -Xmx1024m . 因此,我决定增加-Xmx1024m来增加堆空间。 The program runs halfway and then it throws the same error again. 程序运行一半,然后再次引发相同的错误。 I am basically trying to extract words from a pdf document (has 10 million words) so that's a big file. 我基本上是试图从pdf文档中提取单词(有1000万个单词),所以这是一个很大的文件。

I tried increasing the value to 5000m but it says invalid maximum heap size the specified size exceeds maximum representable size . 我尝试将值增加到5000m但它表示invalid maximum heap size the specified size exceeds maximum representable size Does anyone know what is the maximum possible size i specify the value so it can run my program completely? 有谁知道我指定的最大可能大小是多少,以便它可以完全运行我的程序?

The value of the JVM heap size is directly related to the amount of physical memory in the system. JVM堆大小的值与系统中的物理内存量直接相关。 Set the initial and maximum heap sizes to 4096 to start tuning, because 32-bit operating systems have an address space limit of 4 GB, regardless of the amount of physical memory in the system. 将初始堆大小和最大堆大小设置为4096以开始调整,因为32位操作系统的地址空间限制为4 GB,而与系统中的物理内存量无关。

  • Talking about default heap size in Java, from Java 6 update 18 there are significant changes in how JVM calculates default heap size in 32 and 64 bit machine and on client and server JVM mode: 谈到Java中的默认堆大小,从Java 6更新18开始,JVM在32位和64位计算机以及客户端和服务器JVM模式下如何计算默认堆大小有了重大变化:

  • Initial heap space and maximum heap space is larger for improved performance. 初始堆空间和最大堆空间较大,以提高性能。

  • Default maximum heap space is 1/2 of physical memory of size upto 192 bytes and 1/4th of physical memory for size upto 1Gig. 默认最大堆空间是最大为192字节的物理内存的1/2,最大为1Gig的物理内存的1/4。 So for 1Gig machine maximum heap size is 256MB 2. maximum heap size will not be used until program creates enough object to fill initial heap space which will be much lesser but at-least 8 MB or 1/64th part of Physical memory upto 1GB. 因此,对于1Gig机器,最大堆大小为256MB2。在程序创建足够的对象来填充初始堆空间之前,将不使用最大堆大小,该空间会小得多,但至少要占用8 MB或物理内存的1/64部分,最高为1GB。

  • for Server Java virtual machine default maximum heap space is 1G for 4GB of physical memory on a 32 bit JVM. 对于Server Java虚拟机,对于32位JVM上的4GB物理内存,默认最大堆空间为1G。 for 64 bit JVM its 32G for a physical memory of 128GB 对于64位JVM,其32G的物理内存为128GB

Also be reminded that increasing memory does not help many times, as actual issue resides in code. 还要提醒您,增加内存并不能解决很多问题,因为实际问题出在代码中。 I would suggest you to use heap analyzer and make sure code has no issues. 我建议您使用堆分析器,并确保代码没有问题。

There is no standard value for this. 没有标准值。 It depends on JVM version, different implementations can have different limits. 它取决于JVM版本,不同的实现可能有不同的限制。

I think you use 32-bit version of JVM. 我认为您使用32位版本的JVM。 From my experience limit is somewhere between 1.5GB and 2GB. 从我的经验来看,限制在1.5GB到2GB之间。

If you use 64-bit operation system you can install 64-bit JVM. 如果使用64位操作系统,则可以安装64位JVM。 It allow you to set virtually any value as max memory size. 它实际上允许您将任何值设置为最大内存大小。

PS: You may think about changing your program to store intermediate results on disk or in database. PS:您可能会考虑更改程序以将中间结果存储在磁盘或数据库中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM