7

Due to a small implementation mistake I discovered how quickly I could reach a Java heap space issue

now the bug is fixed everything is fine but it did get me looking into how to solve this and I foudn multiple solution such as

java -Xms5m -Xmx15m MyApp

the problem is that this changes the java memory on my computer, but I'm working on a Applet that is going to be used in a webrowser.

Therefore, is there a way, at RUNTIME in an APPLET to change the heap size ?

4

4 回答 4

10

您可以将参数添加到小程序标签。但是您感兴趣的参数仅在 Java6 u10 或更高版本上可用。

例子:

<APPLET archive="my_applet.jar" code="MyApplet" width="300" height="300">
    <PARAM name="java_arguments" value="-Xmx256m">
</APPLET>

这里有更多信息http://www.oracle.com/technetwork/java/javase/plugin2-142482.html#JAVA_ARGUMENTS

于 2011-02-17T08:07:05.773 回答
2

AFAIK,只有用户可以更改 JRE 堆设置。Applet 无法更改此设置。

更新:

似乎在最新版本的 JDK 中这是可能的。看:如何启动一个内存更大的Java小程序?

更新2:

内存设置只能为 JNLP 应用程序设置,不能为小程序设置。

于 2011-02-17T07:59:55.690 回答
1

如果未在命令行中指定,则必须从 JVM 设置中获取。因此,当您将小程序部署到 Web 时,这将取决于他们在运行时计算机上的内存设置。通常默认设置为 60-90Mb,因此请尽量保持在该值以下。

如果小程序可以更改这些设置,请考虑后果......它还可以更改什么。那只是最终要求安全漏洞,而Java的目标是在功能之前实现安全性:)

于 2011-02-17T08:01:09.370 回答
1

JVM 可能早在您使用 Applet 之前就已启动。现在改变堆大小为时已晚。尝试 Java Web Start,您可以在其中控制它,为您的 Applet/应用程序生成一个新的 JVM。

于 2011-02-17T08:02:13.030 回答