Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set default heap size in Windows [duplicate]

Tags:

I want to set Java heap size permanently and don't want to run every jar file with options. I use Windows and Java 1.7.

like image 960
Reza Ameri Avatar asked Jun 28 '13 16:06

Reza Ameri


People also ask

How increase JVM heap size permanently?

Edit the -Xmx256m option. This option sets the JVM heap size. Set the -Xmx256m option to a higher value, such as Xmx1024m.

What is the default heap size?

The default maximum heap size value is 256 MB .

What is the default Xms and XMX?

The flag Xmx specifies the maximum memory allocation pool for a Java virtual machine (JVM), while Xms specifies the initial memory allocation pool. The Xms flag has no default value, and Xmx typically has a default value of 256 MB.


2 Answers

Setup JAVA_OPTS as a system variable with the following content:

JAVA_OPTS="-Xms256m -Xmx512m"

After that in a command prompt run the following commands:

SET JAVA_OPTS="-Xms256m -Xmx512m" 

This can be explained as follows:

  • allocate at minimum 256MBs of heap
  • allocate at maximum 512MBs of heap

These values should be changed according to application requirements.

EDIT:

You can also try adding it through the Environment Properties menu which can be found at:

  1. From the Desktop, right-click My Computer and click Properties.
  2. Click Advanced System Settings link in the left column.
  3. In the System Properties window click the Environment Variables button.
  4. Click New to add a new variable name and value.
  5. For variable name enter JAVA_OPTS for variable value enter -Xms256m -Xmx512m
  6. Click ok and close the System Properties Tab.
  7. Restart any java applications.

EDIT 2:

JAVA_OPTS is a system variable that stores various settings/configurations for your local Java Virtual Machine. By having JAVA_OPTS set as a system variable all applications running on top of the JVM will take their settings from this parameter.

To setup a system variable you have to complete the steps listed above from 1 to 4.

like image 158
Bogdan Emil Mariesan Avatar answered Sep 22 '22 14:09

Bogdan Emil Mariesan


Try setting a Windows System Environment variable called _JAVA_OPTIONS with the heap size you want. Java should be able to find it and act accordingly.

like image 40
Alex Kibler Avatar answered Sep 18 '22 14:09

Alex Kibler