How to increase java heap size programmatically

Setting -Xmx to one gig doesn’t mean that the JVM will allocate that much memory upon start-up. The JVM will allocate only -Xms (plus overhead) until more heap space is needed. Do you need to protect your users from thrashing virtual memory or a failed memory allocation from the OS? If not, just set Xmx to a large value. Note that Windows 32bit JVMs will often ignore Xmx settings greater than 1.2Gig, so it’s best to not request more than a gig or so to be safe.

Leave a Comment