In many cases, web applications give OutOfMemoryError when their threads require high levels of memory. Image manipulation or intensive database use or calculation can lead to this very common problem.
Normally when you get an OutOfMemory error in a desktop application, you can solve this problem by specifying the java commands -Xms*** (initial Java heap size) and -Xmx*** (maximum Java heap size) when running your program.
To solve this issue in tomcat, you must specify these options in the tomcat startup command / script / batch. In windows tomcat is installed as a service. Tomcat provides a configuration tool to set up these and other parameters. you can find it in (Start->Programs->Apache Tomcat->Configure Tomcat) or by running (.\bin\tomcat5w.exe” //EN//Tomcat5).
Under the “Java” tab you can find two options:
- Initial memory pool: This corresponds to -Xms, you can specify the size in Mb.
- Maximum memory pool: This corresponds to -Xmx, you can specify the size in Mb.
Now you can specify a higher maximum memory so that Tomcat doesn’t get the OutOfMemoryError. Remember to take in consideration your hardware capabilities.