How do I change Java Runtime Parameters?

104,176

Solution 1

If I am not mistaken they are the same in Linux. With the Java command you have the 2 options:

  • Xmx sets the maximum memory heap size.
  • Xms sets the minimum memory heap size.

So doing -Xmx1024m -Xms128m should work.

Here is an extract from doing a man java in the terminal

-Xmsn
                Specify the initial size, in bytes, of the memory allocation
                pool. This value must be a multiple of 1024 greater than 1MB.
                Append the letter k or K to indicate kilobytes, or m or M to
                indicate megabytes. The default value is chosen at runtime
                based on system configuration. For more information, see
                HotSpot Ergonomics
                Examples:

                       -Xms6291456
                       -Xms6144k
                       -Xms6m

 -Xmxn
                Specify the maximum size, in bytes, of the memory allocation
                pool. This value must a multiple of 1024 greater than 2MB.
                Append the letter k or K to indicate kilobytes, or m or M to
                indicate megabytes. The default value is chosen at runtime
                based on system configuration. For more information, see
                HotSpot Ergonomics
                Examples:

                       -Xmx83886080
                       -Xmx81920k
                       -Xmx80m

So that basically sums it up about doubts using the same parameters.

To use this go to a terminal and type it with a jar program. In my example I am using the minecraft server: java -Xms1024M -Xmx2048M -jar minecraft.jar.

Here is an image of what happens:

enter image description here

I should note that the parameters are Case Sensitive. So xmx1024M is not the same as Xmx1024M.

Solution 2

The same applies on Linux. If you want to make the options permanent, you can export the JAVA_OPTS environment variable.

I recommend to do it on a per-user basis. Modify the .profile file in your home directory (or .bash_profile if it exists and you use bash) to include this line:

export JAVA_OPTS='-Xincgc -Xmx2048M'

After setting this, you need to restart shell sessions for it to apply.

Alternatively, you can also modify the system-wide profile in /etc/profile.

Edit: Settings for the Java Browser Plugin are defined in the Java Control Panel: http://docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/control_panel.html.

Share:
104,176
Andri
Author by

Andri

Updated on September 18, 2022

Comments

  • Andri
    Andri over 1 year

    On Windows, I could change how much RAM Java could use by typing something like -Xincgc -Xmx2048M in the Java Runtime Parameters. How can I do that in Ubuntu?

  • Andri
    Andri about 12 years
    Well, I didn't ask what parameters I should use. I asked where I should type the parameters. If I type -Xmx1204m -Xms128m, it says unknown command.
  • Andri
    Andri about 12 years
    How does the same apply to Linux? I can't go to Control Panel, open Java and change the settings. What do I do?
  • jjmontes
    jjmontes about 12 years
    If I'm not wrong, that control pannel applies only to the Java Plugin for the Browser. If that is what you look for,it is located at /jre/bin/ControlPanel (docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_gu‌​ide/…)
  • Andri
    Andri about 12 years
    That's not what I meant. All I need to know is how I could make Java be able to use more RAM than it does now.