Setting Launch Parameters In Java Class

拟墨画扇 提交于 2019-12-12 15:16:14

问题


Is there a way to make it so you can set memory usage arguments inside a java class, not using eclipse or a java program compiler, just simple code that you can do inside a class using notepad or something. If you don't know what I mean, Here's an example:

public class Example {
   public Example() {
     -Xmx("1024M");
   }

   public static void main(String args[]) {
     new Example();
   }
}

Please help, thank you! Note: I don't want to make a cmd/batch file to run it with -Xmx!


回答1:


The memory cannot be changed at run-time (by the time the JRE gets to your code statement, the memory has been set & cannot be changed). The only way to achieve a different memory size is to relaunch the app. using a Process specifying larger memory (then close the original app. that does not have enough).

Of course, better to simply specify the required memory in the launch process (BAT file, JWS etc.).



来源:https://stackoverflow.com/questions/10936046/setting-launch-parameters-in-java-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!