Thursday, March 4, 2010

Increasing Java Heap Size & Largest prime Number

Today I was trying to do this nonsense of computing large prime numbers....
Very soon I found out that the largest prime number known as of now "contains 13 million digits".
More details can be seen on wikipedia.

Well jokes apart......
I am using java and I came across the fact that the default maximum size of java heap is 128 M.
This is truly frustrating as for large scale applications this is sure to give "java.lang.OutOfMemoryError: Java heap space" error or may be slow results.

We can simply increase the heap space by providing a VM arguement with the program.

For eg if ur java class name is MyJava.class. You can run the program with increased heap size uing the command:

>>java -Xmx256m MyJava

or in case of IDEs just supply the vm args under the Arguements tab as -Xmx256m and run the program.

This is an example to run program with heap size 256m, you can use any desired value provided that you have the resources.

Note: This is not a permanent change to the jvm,,,, heap space is permited only for once for the specific deployement.

No comments:

Post a Comment