简体   繁体   English

如何增加JVM堆大小

[英]How to increase JVM heap size

I have followed some of the posts in increase JVM heap size Stack Overflow to increase the JVM heap size. 我已经关注增加JVM堆大小 Stack Overflow中的一些帖子,以增加JVM堆大小。 I set environment variables as suggested above link. 我按照上面链接的建议设置环境变量。

I executed below program, to check, what is the max heap size. 我执行下面的程序,以检查最大堆大小是多少。

public class GetHeapSize {
     public static void main(String[]args){

            //Get the jvm heap size.
            long heapSize = Runtime.getRuntime().totalMemory();

            //Print the jvm heap size.
            System.out.println("Heap Size = " + heapSize);
        }

}

I got output before setting and after setting is same as 16252928 我在设置之前和设置之后都得到了与16252928相同的输出

Please can anyone suggest how can I increase heap size? 请任何人建议我如何增加堆大小?

The totalMemory() reports the current size of the heap. totalMemory()报告堆的当前大小。 If you want the maximum size that the heap will grow to, call maxMemory() instead. 如果要让堆增长到最大大小,请调用maxMemory() The javadoc says: Javadoc说:

"Returns the maximum amount of memory that the Java virtual machine will attempt to use. If there is no inherent limit then the value Long.MAX_VALUE will be returned." “返回Java虚拟机将尝试使用的最大内存量。如果没有固有限制,则将返回Long.MAX_VALUE值。”

and then says that the amount is measured in bytes. 然后说该数量以字节为单位。

in the common case the Heap size grows dynamically, so that you can use -Xmx option to limit the high size of the heap and -Xms option to set the start size of the heap and you can make them the same on the start, so that the JVM will not spend resources for dynamic memory operations. 在通常情况下,堆大小会动态增长,因此您可以使用-Xmx选项来限制堆的高大小,并可以使用-Xms选项来设置堆的开始大小,并使它们在开始时相同。 JVM将不会花费资源进行动态内存操作。 Also may be it would be interesting for you to use more informative JMX way to get heap size through the MemoryMXBean bean. 对于您来说,使用更具信息性的JMX方法通过MemoryMXBean bean获取堆大小可能也会很有趣。

MemoryMXBean MEMORYMXBEAN = ManagementFactory.getMemoryMXBean();

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

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