Why an executable jar when run from a command line uses much more RAM - in my case around 7 time more - than the same project run from Eclipse?
While developing the project I run the application from Eclipse (Run->Run) it used around 60mb (I looked at the just created javaw.exe process) of ram, whereas if I create an executable JAR and run it from command line (Windows) the ram usage is about 450mb. Also, the amplitude of ram usage change is more when run from the command line, than from Eclipse's Run->Run.
This is probably to do with the JVM settings that Eclipse launches the application with. When launching the Jar, Java will make a best guess at what settings to use in terms of memory. You can change the size of the memory used with the the java
command on the console:
java -Xms64m -Xmx256m -cp your.jar
-Xms??m
sets the minimum heap size in mb.-Xmx??m
sets the maximum heap size in mb.
Java is probably automatically choosing a larger heap size automatically as it is not being dictated by eclipse.
In eclipse it has to share the ram with other services/application. But on command line it has no restriction. On command line you have also the possibility to limit ram by launching the application. You can limit it by doing this
java -Xmx256M -Xms256M -cp /*.jar
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With