views:

132

answers:

4

Considering the following command line

java -Xms128m -Xms256m myapp.jar

Which settings will apply for JVM Minimum memory (Xms option) : 128m or 256m ?

+4  A: 

Depends on the JVM, perhaps the version...perhaps even how many paper clips you have on your desk at the time. It might not even work. Don't do that.

If it's out of your control for some reason, compile and run this the same way you'd run your jar. But be warned, relying on the order of the options is a really bad idea.

public class TotalMemory
{
    public static void main(String[] args)
    {
         System.out.println("Total Memory: "+Runtime.getRuntime().totalMemory());
         System.out.println("Free Memory: "+Runtime.getRuntime().freeMemory());
    }
}
cHao
+1 - better count those paperclips :-). Seriously, it is not rocket science to change whatever is passing those ambiguous arguments.
Stephen C
+1  A: 

I bet it's the second one. Arguments are usually processed in the order:

for( int i=0; i<argc; i++ ) {
  process_argument(argv[i]);
}

But if I were writing java argument parser, I'd complain on conflicting arguments.

Vladimir Dyuzhev
+1  A: 

The IBM JVM treats the rightmost instance of an argument as the winner. I can't speak to HotSpot, etc..

We do this as there are often deeply nested command lines from batch files where people can only add to the end, and want to make that the winner.

Trent Gray-Donald
A: 

There is a wrongly typed question java -Xms128m -Xms256m myapp.jar

this is supposed to be java -Xms128m -Xmx256m myapp.jar

Then the following line explains your query

The heap size may be configured with the following VM options:

* -Xmx<size> - to set the maximum Java heap size
* -Xms<size> - to set the initial Java heap size

Which settings will apply for JVM Minimum memory (Xms option) : 128m or 256m ? 256 Mb would be your maximum Memory 128 Mb would be initial set Memory.

Along with this, if you want to determine programmatically you can use the following Sample code

 Runtime runtime = Runtime.getRuntime();

    NumberFormat format = NumberFormat.getInstance();

    StringBuilder sb = new StringBuilder();
    long maxMemory = runtime.maxMemory();
    long allocatedMemory = runtime.totalMemory();
    long freeMemory = runtime.freeMemory();
harigm
This is not wrongly typed. Read the title and contents of the question again!
fabien7474