我发现我们正在使用的旧版软件的启动属性格式错误,因此它接收这两个不相等的 xmx 作为属性:
java -jar myapp.jar -Xmx128m -Xmx512m
我无法访问启动器源代码(无法修改它),所以我问,这些参数重复有什么影响?我可以这样离开吗,还是我应该担心?哪一个会被应用?
使用的 JVM 是 JRE 6 update 18
In general, it's usually the latter option that gets used if a tool doesn't reject a duplicate, but you can't count on that unless the tool documents it.
Your best bet is to see what happens with your specific JVM, via Runtime
's totalMemory
and maxMemory
:
public class HeapSize {
public static final void main(String[] args) {
Runtime rt = Runtime.getRuntime();
System.out.println("Total currently: " + rt.totalMemory());
System.out.println("Max: " + rt.maxMemory());
System.exit(0);
}
}
On my JVM (Sun/Oracle 1.6.0_26-b03 under Linux), the latter option takes effect:
$ java -Xmx16m HeapSize Total currently: 16121856 Max: 16121856 $ java -Xmx32m HeapSize Total currently: 32178176 Max: 32178176 $ java -Xmx16m -Xmx32m HeapSize Total currently: 32178176 Max: 32178176 $ java -Xmx16m -Xmx32m -Xmx128m HeapSize Total currently: 59113472 Max: 119341056
我的理解是它将使用最后一个设置。