View RSS Feed

Advanced Java

Advanced Java programming.

  1. Getting Java Heap Size

    by , 02-18-2012 at 03:29 PM
    In JVM, heap size is considered as a main area. New objects are stored or created here. To get heap size, see this Java code. We will also be considering various memory methods.

    Java Code: This is the code to get the heap size in Java
    // Get current size of heap in bytes
    long heapSize = Runtime.getRuntime().totalMemory();
    
    // Get maximum size of heap in bytes. The heap cannot grow beyond this size.
    // Any attempt will result in an OutOfMemoryException.
    long heapMaxSize = Runtime.getRuntime().maxMemory();
    ...
    Categories
    Memory
  2. How to manage Java Heap Size?

    by , 02-18-2012 at 03:25 PM
    You can specify the memory allocation for JVM using X option. Following table explains the JVM options.

    -Xms: initial java heap size
    -Xmx: maximum java heap size
    -Xmn: the size of the heap for the young generation

    unix> bin/httpd.sh -Xmn100M -Xms500M -Xmx500M
    win> bin/httpd.exe -Xmn100M -Xms500M -Xmx500M
    install win service> bin/httpd.exe -Xmn100M -Xms500M -Xmx500M -install

    To set max Xmx and min Xms heap sizes ...
    Categories
    Memory