Java 堆空间:小程序 [英] Java Heap Space: Applets

查看:28
本文介绍了Java 堆空间:小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写一个程序来处理 3000*3000 矩阵.它只能工作到 600*600.

I had to write a program to work for a 3000*3000 matrix. It was working only up to 600*600.

所以我通过 java -Xms64m -Xmx1024m <class_name> 增加堆大小来运行我的程序因为最初发生了 OutOfMemoryError.这解决了问题.

So I ran my program by increasing heap size by java -Xms64m -Xmx1024m <class_name> Because initially the OutOfMemoryError was occurring. That solved the problem.

现在这个相同的程序用于在 Applets 中绘制值.所以我做了一个包并导入它.但是随后出现了同样的错误,因为您无法运行一个小程序.

Now this same program is used to plot values in Applets. So I made a package and imported it. But then the same error was coming as you can't run an applet.

您只能键入javac class_name.javaappletviewer class_name.java.

所以我无法增加堆大小.所以我特意放了一个 main() 函数......它计算了要绘制的值(存储在数组中).

So there was no way I could increase heap size. So I purposely put a main() function...which calculated the values to be plotted(stored in an array).

然后小程序会打印它们.并且数组是静态的和全局的.

And the applet would print them. And the array was static and global.

然后我编译(javac class_name.java)并运行(java -Xms64m -Xmx1024m )然后输入appletviewer class_name.java.

Then I compiled (javac class_name.java)and ran(java -Xms64m -Xmx1024m <class_name>) and then typed appletviewer class_name.java.

但是 0,0,0,... 显示出来了.基本上是 int 数组的默认值.

But 0,0,0,... got displayed. Basically the default values of int array.

就好像 main() 函数从未运行过一样.即使数组是全局的.

As though the main() function never ran. Even though array was global.

最终,我只需要一个 main() 函数......以及一些存储值并在输入 ppletviewer class_name.java 时保留它们的变量.

Ultimately, I just need a main() function... and some variable that stores values and retains them when ppletviewer class_name.java is typed.

有没有办法做到这一点?或者增加小程序的堆大小?

Is there any way to do this? Or else to increase heap size for applets?

因为当我在 init()paint() 函数中输入逻辑时,会出现同样的错误 (OutOfMemoryError)

Because when I type the logic in init() or paint() function the same error comes (OutOfMemoryError)

推荐答案

您可以在包含小程序的 HTML 中指定 JVM 参数,例如

You can specify JVM parameters in the HTML which contains the applet, e.g.

<APPLET archive="applet.jar" code="ClassName" width="300" height="300">
    <PARAM name="java_arguments" value="-Xms64m -Xmx1024m">
</APPLET>

请参阅 Oracle 关于小程序部署的文档

这篇关于Java 堆空间:小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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