How to increase Java Heap Memory

Java applet throws out of memory exception when run with large data. The error will look like this
Exception in thread "AWT-EventQueue-2" java.lang.OutOfMemoryError: Java heap space
 at java.util.Arrays.copyOf(Unknown Source)
 at java.io.ByteArrayOutputStream.write(Unknown Source)
 at java.util.zip.DeflaterOutputStream.deflate(Unknown Source)
 at java.util.zip.DeflaterOutputStream.write(Unknown Source)
 at java.util.zip.ZipOutputStream.write(Unknown Source)
 at client.utils.Util.zip(Util.java:556)
Reason for error:

When running Java Applet, Java uses default heap memory allocated for jvm. You can 
either increase or decrease this memory as follows:
There are two values for memory allocation, -Xmsn and -Xmxn:
-Xmsn is initial size of the memory allocation pool, the default value is 2MB.
-Xmxn is maximum of the memory allocation pool, the default value is 64MB.

If you want more memory allocated for your JVM, you can specify these value in your JVM args, 
set it through Java control panel in client's machine.
Example to allocate 900m

java -Xmx900m your-class-Here
References:
How to increase applet memory 
bugs.sun.com link 

Related Posts with Thumbnails