What's the reason to set a minimal Java Heap S

2019-07-07 03:10发布

问题:

I can set the Java Heap Size minimum and maximum by passing the parameters -Xms and -Xmx, respectively.

I understand that the maximum flag is necessary to limit the space, but what's the reason for setting a minimum initial heap size? If the maximum is big enough, the space will increase? Or do i miss something?

回答1:

Minimun size is set so that the JVM doesn't have to "resize" the heap space if it starts off too small.



回答2:

Java will start with the minimum heap size and will try to avoid enlarging the heap by garbage collecting.

So if the steady-state memory size of your app is larger than the default heap minimum heap size, you may do a lot of pointless GC on the way to that size. Setting the min size to that size will avoid the pointless GC.



回答3:

You can set the minimum heap size if your application needs a certain amount to run. If you set the maximum heap size, the jvm isn't supposed to exceed it.