Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why an executable jar when run from a command line uses much more ram, than the same project run from Eclipse?

Tags:

java

eclipse

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.

like image 234
Mr.Zeiss Avatar asked Dec 19 '12 21:12

Mr.Zeiss


2 Answers

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.

like image 102
Tom Cammann Avatar answered Oct 15 '22 00:10

Tom Cammann


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
like image 23
Festus Tamakloe Avatar answered Oct 15 '22 01:10

Festus Tamakloe