Managing the memory heap 

Anyone who has worked with Java-based applications would have surely come across setting the heap space. We do it using -Xms and -Xmx. Suppose I set following the command-line option:

-Xms256m -Xmx2048m

Here, Xms specifies our initial memory allocation pool, whereas Xmx specifies the maximum memory allocation pool for JVM. In the case we just saw, our JVM will start with 256 MB of memory and will be able to use up to 2 GB of memory.

If we require more heap space, then we can increase -Xms. We can also decide not to give any initial heap space at all and let JVM use the heap space as per the need, but this may increase our startup time. Similarly, failing to set up the maximum heap size properly can result in OutOfMemoryException. Proper garbage collection JVM parameters should be set so that JVM can optimally try to reclaim any available space that already exists in the heap. Also, the size of the heap plays a crucial role in garbage collection. The larger the heap size, the more the time spent by JVM to do garbage collection, leading to stop the world conditions.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.199.140