This is especially useful in Vaadin apps as the state all lives in web sessions in the Tomcat server. So those sessions tend to eat up memory.
My research into this topic was long and frustrating. For one thing, much discussion involves "PermGen" which is now outmoded. Current updates to Java 8 have eliminated the PermGen, so memory management is now more straightforward.
Eventually I learned one simple way to allocate memory to Tomcat 8. The following steps work on with the Oracle release of Java 8 on Mac OS X Mountain Lion. The steps probably work on any Unix-oriented system such as BSD or Linux. Don’t know about Microsoft Windows. The "-X" flags are optional, not required by the Java spec; so other non-Oracle implementations of Java may not respect these flags.
- Locate your Tomcat folder, and the nested the "bin" folder.
- Create a text file named exactly "setenv.sh".
- Add one line to the file:
export JAVA_OPTS="-Xms6144m -Xmx6144m"
Those two numbers should be what ever number of megs you want. So 6,144 megs is 6 gigs. I don’t know if it is required, but I would use multiples of 1024. So 6 * 1024 = 6,144.
By setting the minimum (Xms) to be the same number as the maximum (Xmx), Tomcat will grab and hold that entire amount of memory. If you set the minimum to be lower, you will see the amount of memory used by Tomcat grow and shrink over time as garbage collection releases memory back to the operating system. I do not know the pros and cons of these two behaviors.