aspose file tools*
The moose likes Tomcat and the fly likes Tomcat Connection pool creating too many connections, stuck in sleep mode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "Tomcat Connection pool creating too many connections, stuck in sleep mode" Watch "Tomcat Connection pool creating too many connections, stuck in sleep mode" New topic
Author

Tomcat Connection pool creating too many connections, stuck in sleep mode

Ben Shoots
Greenhorn

Joined: Apr 27, 2011
Posts: 1
I'm using Tomcat 7's connection pool with MySQL. Testing my application, it doesn't reuse anything from the pool, but ends up creating a new pool, to eventually where I cannot use the database because there are hundreds of sleeping connections in the pool when the max active size for the pool is set to 20.

See here for reference:

It creates exactly 10 for each request, which is the minIdle attribute as seen below.

Here is the sample test code embedded into a jsp page. The code is not the code in my application and just used to see if the issue was with my code, but the problem still persisted.



Here is my context.xml file:



I'm sure I can use removeAbandonedTimeout to a low number and it would purge all these sleeping connections, but that wouldn't fix the real problem would it? Does anyone know what I'm doing wrong?

Thank you very much,
Ben
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16305
    
  21

I heartily recommend NEVER ignoring exceptions. Dump the stacktrace to the log, but don't just drop them. Otherwise when things go mysteriously wrong, you won't have a clue.

There is a DBCP option that allows tracking connections. What it does is generate an Exception (with associated stacktrace) when you request a connection from the pool. This Exception is then attached to the Connection instead of being thrown. If the orphan connection cleanup service picks up an abandoned connection of this type, it prints the stacktrace, which tells you what part of the app is creating improperly-released connections.

The orphan connection problem is one reason I like the Spring Framework. It manages the grunt work, including ensuring that connections get returned to the pool.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat Connection pool creating too many connections, stuck in sleep mode