简体   繁体   English

为什么从命令行运行可执行jar比使用Eclipse运行的同一个项目使用更多的ram?

[英]Why an executable jar when run from a command line uses much more ram, than the same project run from 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? 为什么从命令行运行时可执行jar使用更多的RAM - 在我的情况下大约多7倍 - 比从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. 在开发项目时,我从Eclipse运行应用程序(运行 - >运行),它使用了大约60mb(我看了刚刚创建的javaw.exe进程)的ram,而如果我创建了一个可执行的JAR并从命令行运行它(Windows公羊的使用量约为450mb。 Also, the amplitude of ram usage change is more when run from the command line, than from Eclipse's Run->Run. 此外,从命令行运行时,ram使用量变化的幅度大于Eclipse的Run-> Run。

This is probably to do with the JVM settings that Eclipse launches the application with. 这可能与Eclipse启动应用程序的JVM设置有关。 When launching the Jar, Java will make a best guess at what settings to use in terms of memory. 在启动Jar时,Java将最好地猜测在内存方面使用的设置。 You can change the size of the memory used with the the java command on the console: 您可以在控制台上更改java命令使用的内存大小:

java -Xms64m -Xmx256m -cp your.jar

-Xms??m sets the minimum heap size in mb. -Xms??m以mb为单位设置最小堆大小。
-Xmx??m sets the maximum heap size in mb. -Xmx??m以mb为单位设置最大堆大小。

Java is probably automatically choosing a larger heap size automatically as it is not being dictated by eclipse. Java可能会自动选择更大的堆大小,因为它不受eclipse的支配。

In eclipse it has to share the ram with other services/application. 在eclipse中,它必须与其他服务/应用程序共享内存。 But on command line it has no restriction. 但是在命令行上它没有任何限制。 On command line you have also the possibility to limit ram by launching the application. 在命令行上,您还可以通过启动应用程序来限制ram。 You can limit it by doing this 你可以通过这样做来限制它

java -Xmx256M -Xms256M -cp /*.jar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM