This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX 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: 17142
    
  27

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.


An IDE is no substitute for an Intelligent Developer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tomcat Connection pool creating too many connections, stuck in sleep mode
 
jQuery in Action, 3rd edition