简体   繁体   中英

Setting Java Heap Size does not work with 256GB RAM 64-bit machine

I have been trying to find the answer to this but I still could not.

I have a 64-bit machine with 256 GB RAM.

I am trying to execute a Java program which links to MySQL. And it needs a quiet big heap size because when I used VM argument -Xmx1024m after few minutes this pops up:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

But, when I tried to set the program VM argument by -Xmx2048m or bigger, it does not work and said:

Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

I read that setting -Xmx2048 is not a problem for 64-bit machine but I really do not know why it's not working on my machine.

java -version output: 在此处输入图片说明

wmic OS get FreePhysicalMemory /Value output:

FreePhysicalMemory=251663664

wmic computersystem get TotalPhysicalMemory output:

TotalPhysicalMemory
274811621376

wmic os get osarchitecture output

OSArchitecture
64-bit

I could not execute systeminfo|find "Memory" as it says wrong syntax. Im not sure why either.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

This message implies the java heap does not have enough space to do further allocation. It seems you have set to 1G of Xmx which is insufficient for your application else the application might leak memory which occupies space in java heap.

Error occurred during initialization of VM
Could not reserve enough space for 2097152KB object heap

During VM initialization. JVM does various init right from Heap to JIT modules. Java heap are continiuos space while doing doing initialization if JVM could not find the contigous memory space for the requested Xmx then above error message will be thrown.

These are virtual memory allocation so please do not confuse with physical memory values

Please run the command java -verbose:init -Xmx2048 -version

this command will tell the steps undergoes by JVM while doing initialization and during what step it got failed.

Consider running your app as an administrator - just launch the PowerShell console via right click -> Run as Administrator.

Windows may deny granting a lot of memory to a single process that is running non-elevated.

Also - are you using Windows Server or a workstation version of Windows? It is generally recommended to use Windows Server for such "big" services.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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