wood burning stoves 2.0*
The moose likes Tomcat and the fly likes OutOfMemoryError from tomcat 5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "OutOfMemoryError from tomcat 5" Watch "OutOfMemoryError from tomcat 5" New topic
Author

OutOfMemoryError from tomcat 5

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi all,

I have tomcat 5.5 and when I run my application for the ~20th time, I get this error message:



I googled this issue and reallied that I should increase the size of allocated heap .

something like this:

java -Xms5m -Xmx15m MyApp


(not sure about the size)

but where exactly do I execute this statement? when I do that in the command line (win) i get this error:
exception in thread "main" java.lanf.noClassDefFoundError: MyApp

also...someone noted that it should be on tomcat as in:

"$_RUNJAVA" -Xmx512M $JAVA_OPTS $CATALINA_OPTS

and yet...could figure it out how to do that.

anyone?!?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

It depends on how you're running Tomcat.

What OS are you using?
How are you starting Tomcat (shell script, batch script, windows service, start menu button)?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Since this only happens after 20 requests, it sounds like your code does not properly manage references to objects that are no longer needed.

Does this application use a database connection? Mishandling DB connection and related objects can run you out of memory in a hurry.

Bill
Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
--What OS are you using?
win xp

--How are you starting Tomcat (shell script, batch script, windows service, start menu button)?
from eclipse (im using the Sysdeo

it sounds like your code does not properly manage references to objects that are no longer needed.
YES! I suspected that this is the issue - but what can I do? I'm also using DB conn extensively.

any idea?
thanks for the help
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
but what can I do?

I suggest reading up on best practices for JDBC in general - ask in the JDBC forum here at the ranch. It has been a while since I used JDBC and Im sure my hints would be out of date.

I do know that it is highly recommended that you use DB connection pools rather than trying to manipulate them directly.

Bill
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

For starters, I would make sure that every method that uses a connection, statement, or resultset, explicitly closes these resources in a finally block.

The commons/dbcp package (what Tomcat uses as it's connection pool manager) overrides the connection.close() method. In their implementation, the close method returns the connection to the pool. So.. if you don't call it, the connection object's reference in the connection pool is kept alive (can't be garbage collected) but can't be reused. This means that the pool has to keep creating connections but can never clean them up.

This is probably the most common form of Memory leak in a Java web application.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: OutOfMemoryError from tomcat 5