I have a Windows 7 laptop, with 16GB RAM. When I run multiple java servers I get OutOfMemory error, however, windows task manager shows that I still have 6GB of free physical memory left. It seems like to me that my JVM can only allocate ~2GB heap for all running java apps.
So I wrote some very simple Java code:
public class HelloWorld {
public static void main(String[] args) {
for(;;) System.out.println("Hello, World");
}
}
My -jvm version:
$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
JAVA_HOME "C:\Program Files\Java\jdk1.8.0_111"
JRE_HOME "C:\Program Files\Java\jre1.8.0_111"
I did a simple java -Xmx256m -Xms256m HelloWorld
and it worked as expected, however when I switched to java -Xmx2048m -Xms2048m HelloWorld
I get the following:
Error occurred during initialization of VM
Could not reserve enough space for object heap
I tried multiple JDKs but none of them are working. Both windows and JVM are in 64 bits.
What can I do to fix this problem?