Search code examples
javajvmlaunch4j

JVM command start options duplication


I have found a legacy software that we're using that has its launch properties malformed, so it receives these two unequal xmx as a properties:

java -jar myapp.jar -Xmx128m -Xmx512m 

I do not have access to the launcher source code(not being able to modify it), so I ask, what is the impact of the duplication of these parameters? Can I leave this in this way, or should I worry? Which one will be applied?

The JVM used is JRE 6 update 18


Solution

  • In general, it's usually the latter option that gets used if a tool doesn't reject a duplicate, but you can't count on that unless the tool documents it.

    Your best bet is to see what happens with your specific JVM, via Runtime's totalMemory and maxMemory:

    public class HeapSize {
        public static final void main(String[] args) {
            Runtime rt = Runtime.getRuntime();
            System.out.println("Total currently: " + rt.totalMemory());
            System.out.println("Max:             " + rt.maxMemory());
            System.exit(0);
        }
    }
    

    On my JVM (Sun/Oracle 1.6.0_26-b03 under Linux), the latter option takes effect:

    $ java -Xmx16m HeapSize
    Total currently: 16121856
    Max:             16121856
    $ java -Xmx32m HeapSize
    Total currently: 32178176
    Max:             32178176
    $ java -Xmx16m -Xmx32m HeapSize
    Total currently: 32178176
    Max:             32178176
    $ java -Xmx16m -Xmx32m -Xmx128m HeapSize
    Total currently: 59113472
    Max:             119341056