1

I was using a tool. The JVM option is configurable.

Recently, I get a OutOfMemoryError so I add -Xmx1024m in the option configuration as below.

The config.properties: JVM_OPTION="-Xmx4096m -XX:-UseGCOverheadLimit"

The cmd log before: java -Xms16777216 -Xmx50m com.f.Startmain

The cmd log now: java -Xms16777216 -Xmx50m com.f.Startmain -Xmx4096m -XX:-UseGCOverheadLimit

The tool is still out of memory now as the -Xmx4096m is not overwrite the old one. The tool is not modifiable, and the configuration is only adding new options at the end of the command.

Could someone know a method to overwrite -Xmx50m in JVM options?

paco alcacer
  • 381
  • 2
  • 13
  • Maybe you just have some memory leak? – Maksym Nov 13 '14 at 09:39
  • @Maksym The default setting is really small. 50MB. This is a big tool which will load many objects. It depends on what db it connect. Now my DB contains a lot of information which need bigger memory to load it. Thanks all the same. – paco alcacer Nov 13 '14 at 09:42
  • look at the start script of the tool and find the place to modify the -Xmx setting. The script seems to append the JVM_OPTION add the end. This results in duplicate -Xmx parameters and the one behind the class name will be ignored. – Udo Nov 13 '14 at 09:44
  • @Udo I will do that if I can. The cmd log shows it. The tool is an exe. – paco alcacer Nov 13 '14 at 09:59

1 Answers1

5

This seems to have been answered here

apparently for both windows and linux, you can set:

export _JAVA_OPTIONS="-Xmx1g"

I ran a quick test and this seems to override the commandline params. (unexpected)

my code:

public class Test {
  public static void main(String[] argv) {
    System.out.println("mem: " + Runtime.getRuntime().freeMemory());
    System.out.println("total mem: " + Runtime.getRuntime().totalMemory());
  }
}

This is the output of running this program

export _JAVA_OPTIONS="-Xmx20m";
java Test
>> Picked up _JAVA_OPTIONS: -Xmx20m
>> mem: 19601168
>> total mem: 20447232

java -Xmx123m Test
>> Picked up _JAVA_OPTIONS: -Xmx20m
>> mem: 19601320
>> total mem: 20447232

# clear java options
export _JAVA_OPTIONS=
java -Xmx123m Test
>> Picked up _JAVA_OPTIONS: 
>> mem: 121773128
>> total mem: 123731968

As you can see, the Xmx value on the commandline is ignored until I clear the _JAVA_OPTIONS.

Community
  • 1
  • 1
Joeblade
  • 1,735
  • 14
  • 22