If your
servlets or JSP pages have any problems and you see "java.lang.OutOfMemoryError" in your log files or in a stack trace generated by the JVM, then you probably need to increase the JVM's maximum heap size.
Each instance of a Java Virtual Machine uses an allocation of memory for all objects, shared among all its threads, called the heap. The default size and some of the features of the heap's behavior are implementation dependent, but most (if not all) implementations allow you to modify the heap's minimum and maximum size, and most provide a default value for these settings.
What setting you choose should be determined by
testing and trial and error. It is highly application and load dependent.
You should not try to catch OutOfMemoryErrors in your application. They are not generally predictable. And when they do happen, there's nothing to be done to recover, because by then the JVM is out of memory and the garbage collector is unable to free any memory for further work.