Sathvik Shetty
Sathvik Shetty

Reputation: 49

Java Heap Space: Applets

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)

Upvotes: 1

Views: 841

Answers (1)

Jon Burgess
Jon Burgess

Reputation: 2115

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

Upvotes: 4

Related Questions