Java Heap Space: Applets

ⅰ亾dé卋堺 提交于 2019-12-11 07:25:05

问题


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

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.

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.

You can only type javac class_name.java and appletviewer class_name.java.

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.

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

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

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

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?

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


回答1:


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>

See Oracle's documentation on applet deployment



来源:https://stackoverflow.com/questions/11201769/java-heap-space-applets

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!