Java webstart max-heap-size 导致JVM无法启动

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3285915/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 01:09:16  来源:igfitidea点击:

Java webstart max-heap-size causes JVM cannot be started

javajvmheapjnlpjava-web-start

提问by Jason Wang

We use java webstart on the client side for a java swing based aplication. Recently we have been experiencing a weird "Cannot start java Virtual machine " error when clicking in the jnlp link.

我们在客户端使用 java webstart 来实现基于 java swing 的应用程序。最近我们在点击jnlp链接时遇到了一个奇怪的“无法启动java虚拟机”错误。

We soon find out its because the max-heap-size setting in the jnlp file was set to 1024m whereas most of the clients PC only have 1 gb physical memory. Set the max-heap-size back to 512m solved the problem. Currently, the relevant line in the jnlp file looks like

我们很快就发现了它,因为 jnlp 文件中的 max-heap-size 设置被设置为 1024m,而大多数客户端 PC 只有 1 GB 物理内存。将最大堆大小设置回 512m 解决了问题。目前,jnlp 文件中的相关行看起来像

 <j2se version="1.5+" initial-heap-size="100m" max-heap-size="512m"/>

I looked into the jnlp spec, but cannot find anything related to the "Java Virtual machine" issue. In theory the max-heap-size should not matter as much as the initial-heap-size. But our experience suggested quite the contrary.

我查看了 jnlp 规范,但找不到与“Java 虚拟机”问题相关的任何内容。理论上,最大堆大小不应该与初始堆大小一样重要。但我们的经验表明恰恰相反。

The client environment:

客户端环境:

Windows XP SP2 ( 32bit ), Internet Explorer 8.06, Memory 1G Note max-heap-size set to 1024m can cause the same problem on a machine with 2G ram.

Windows XP SP2(32 位),Internet Explorer 8.06,内存 1G 注意 max-heap-size 设置为 1024m 会在具有 2G 内存的机器上导致同样的问题。

Basically, what I am looking for here is some reference/spec/experience about why this is happening, and if there is any get-round for this issue besides increasing the physical memory size.

基本上,我在这里寻找的是一些关于为什么会发生这种情况的参考/规范/经验,以及除了增加物理内存大小之外是否还有解决此问题的方法。

Another thing is that if we leave the max-heap-size unspecified, will the actual physical memory size be used as the max-heap-size, or a system-default one will be used?

另一件事是,如果我们不指定最大堆大小,实际物理内存大小将用作最大堆大小,还是将使用系统默认大小?

Thanks, JasonW

谢谢,杰森

回答by Jason Wang

It is likely that this problem is caused by the fact that a sufficiently large memory area could not be allocated to your JVM. The Java object heap has to be allocated in contiguous virtual addresses, for implementation reasons.

此问题很可能是由于无法将足够大的内存区域分配给您的 JVM 造成的。出于实现的原因,必须在连续的虚拟地址中分配 Java 对象堆。

I noticed that on a Win XP box with 2 Gb RAM this breaks at around 1.5 GB (this off course varies depending on what processes are running on each PC, so YMMV).

我注意到,在具有 2 Gb RAM 的 Win XP 机器上,这会在 1.5 GB 左右中断(这当然取决于每台 PC 上运行的进程,所以 YMMV)。

Checkout the following posts for some explanations:

查看以下帖子以获取一些解释:

Java maximum memory on Windows XP

Windows XP 上的 Java 最大内存

Why is the maximum size of the Java heap fixed?

为什么 Java 堆的最大大小是固定的?

回答by sullivan-

I found that both the initial-heap-size and max-heap-size were not well respected by the Mac version of javaws. I ended up replacing them with something like this:

我发现initial-heap-size 和max-heap-size 在Mac 版本的javaws 中都没有得到很好的尊重。我最终用这样的东西替换了它们:

      <j2se version="1.6+" java-vm-args="-Xmx1024m -Xms256m -Xss8m" />

And finally got it working on Mac with the larger heap size

最后让它在更大堆大小的 Mac 上运行