在 Java 类中设置启动参数 [英] Setting Launch Parameters In Java Class

查看:30
本文介绍了在 Java 类中设置启动参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法让你可以在java类中设置内存使用参数内部,而不是使用eclipse或java程序编译器,只是简单的代码,你可以使用记事本在类中执行或者其他的东西.如果你不明白我的意思,这是一个例子:

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();
   }
}

请帮忙,谢谢!注意:我不想制作一个 cmd/batch 文件来用 -Xmx 运行它!

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

推荐答案

内存不能在运行时更改(当 JRE 到达您的代码语句时,内存已设置且无法更改).实现不同内存大小的唯一方法是重新启动应用程序.使用 Process 指定更大的内存(然后关闭没有足够内存的原始应用程序).

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).

当然,最好在启动过程中简单指定所需内存(BAT文件,JWS等等.).

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

这篇关于在 Java 类中设置启动参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆