Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OutOfMemoryError from tomcat 5

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
--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
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic