0

Do we need to mandatory specify JVM heap memory arguments in bat file while calling .jar file?

For example: start /b "" "jre7\bin\javaw.exe" -Xmx1G -jar XYZ.jar

I have the scenario that in some machine when I explicitly specify the arguments(as above) then Java fatal exception is generated!

enter image description here

Error Message: "Java virtual machine Launcher: Error: Could not create Java virtual machine. Error: A fatal exception has occurred. Program will exit."

But when I remove the arguments then no error is reported. Please anyone let me know. Thank you.

2 Answers2

0

You need to update the windows environment variables _JAVA_OPTIONS and set Xmx1024M there. Once done you can start your JVM just fine.

Pulkit Gupta
  • 949
  • 2
  • 11
  • 31
  • Thanks for the answer. I wanted to know, if I dont specify the arguments then will the JVM itself taks care of allocating the memory? – Raghu Bhagwat Jul 06 '17 at 06:55
  • Java on Windows uses an initial size of 16 Megabyte and a maximum of 64 Megabyte. But once you set the _JAVA_OPTIONS then whenever JVM starts, it parses the value of _JAVA_OPTIONS as if the parameters were at the command line of java. You can see the passed parameters via JVisualVM. So if you have specified your minimum and maximum requirements in _JAVA_OPTIONS then you are good to go. – Pulkit Gupta Jul 06 '17 at 06:59
  • Must be something was missed in the configuration or the version of the JDK. You can refer this for more details : https://stackoverflow.com/questions/17781405/information-about-java-options – Pulkit Gupta Jul 06 '17 at 07:01
  • Do we need to set this _JAVA_OPTIONS mandatory for any application? – Raghu Bhagwat Jul 06 '17 at 07:02
  • This is an environment variable. If you are setting this then all the jvms started on your host will use this as this is host wide. https://www.computerhope.com/issues/ch000549.htm : This will help you in understanding more about environment variables in Windows. – Pulkit Gupta Jul 06 '17 at 07:04
  • I observed strange behaviour. If I specify heap size as -Xmx1G, then application fails to load. No response! But if I remove it then it works! What would be the problem here? There is no value is set in environment variable path. Kindly suggest the solution. – Raghu Bhagwat Sep 11 '17 at 04:25
0

Xmx is an optional argument that specifies the maximum heap size that can be used by Java. It is not required.

If you specify too large a number, you may get a fatal exception. If you don't specify an option, java chooses the max heap size. You can find the default value of this on linux by running 'java -XX:+PrintFlagsFinal -version | grep MaxHeapSize'

Evan Darke
  • 604
  • 4
  • 7