如何覆盖JVM选项中的-Xmx50m? [英] How to overwrite the -Xmx50m in JVM options?

查看:369
本文介绍了如何覆盖JVM选项中的-Xmx50m?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用工具. JVM选项是可配置的.

I was using a tool. The JVM option is configurable.

最近,我收到了OutOfMemoryError,因此在如下所示的选项配置中添加了-Xmx1024m.

Recently, I get a OutOfMemoryError so I add -Xmx1024m in the option configuration as below.

config.properties: JVM_OPTION =-Xmx4096m -XX:-UseGCOverheadLimit"

The config.properties: JVM_OPTION="-Xmx4096m -XX:-UseGCOverheadLimit"

之前的cmd日志: java -Xms16777216 -Xmx50m com.f.Startmain

The cmd log before: java -Xms16777216 -Xmx50m com.f.Startmain

cmd日志现在: java -Xms16777216 -Xmx50m com.f.Startmain -Xmx4096m -XX:-UseGCOverheadLimit

The cmd log now: java -Xms16777216 -Xmx50m com.f.Startmain -Xmx4096m -XX:-UseGCOverheadLimit

该工具现在仍然内存不足,因为-Xmx4096m不会覆盖旧的工具.该工具不可修改,并且配置仅在命令末尾添加新选项.

The tool is still out of memory now as the -Xmx4096m is not overwrite the old one. The tool is not modifiable, and the configuration is only adding new options at the end of the command.

有人可以知道在JVM选项中覆盖-Xmx50m的方法吗?

Could someone know a method to overwrite -Xmx50m in JVM options?

推荐答案

显然,对于Windows和Linux,您都可以设置:

apparently for both windows and linux, you can set:

export _JAVA_OPTIONS="-Xmx1g"

我进行了快速测试,这似乎覆盖了命令行参数. (出乎意料)

I ran a quick test and this seems to override the commandline params. (unexpected)

我的代码:

public class Test {
  public static void main(String[] argv) {
    System.out.println("mem: " + Runtime.getRuntime().freeMemory());
    System.out.println("total mem: " + Runtime.getRuntime().totalMemory());
  }
}

这是运行该程序的输出

export _JAVA_OPTIONS="-Xmx20m";
java Test
>> Picked up _JAVA_OPTIONS: -Xmx20m
>> mem: 19601168
>> total mem: 20447232

java -Xmx123m Test
>> Picked up _JAVA_OPTIONS: -Xmx20m
>> mem: 19601320
>> total mem: 20447232

# clear java options
export _JAVA_OPTIONS=
java -Xmx123m Test
>> Picked up _JAVA_OPTIONS: 
>> mem: 121773128
>> total mem: 123731968

如您所见,在我清除_JAVA_OPTIONS之前,命令行上的Xmx值将被忽略.

As you can see, the Xmx value on the commandline is ignored until I clear the _JAVA_OPTIONS.

这篇关于如何覆盖JVM选项中的-Xmx50m?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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