문제

I am writing a Java program and at some point during execution I want to change the JVM settings (decrease the heap) and after a while increase it again. Is it possible with Java?

도움이 되었습니까?

해결책

Long story short: you can't. Heap size is fixed once you are running it, and there's no way to modify it from the code.

다른 팁

I do not think this is possible, but you could of course control the heap with -Xmx or -Xms. You can also play with : -XX:MaxHeapFreeRatio : this is the maximum percentage (70 by default if I am no mistaken) of the heap that is free before GC will shrink it.

Giving a small -Xms will make the heap grow (if needed and will involve a full GC) and shrink back is possible also.

Generally people try to avoid as much as possible this shrinking and growing because it involves a gull GC aka stop-the-world events that will slow you down.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top