This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Servlets and the fly likes is jdbc connection deadly for application servers ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "is jdbc connection deadly for application servers ?" Watch "is jdbc connection deadly for application servers ?" New topic

is jdbc connection deadly for application servers ?

heiner weilandt
Ranch Hand

Joined: Sep 10, 2002
Posts: 46
i have developed some web applications with directly jdbc-connections. i know that connection pooling is much faster and better, but can the jdbc-connections bring the application server to dead ? the page vies per days is 60 (quiet low) !
(performance and on shutdown to an unsecure standing)
some of my colleges say, that is deadly, but is this true ?
the server can be hang up by simple jdbc-connections on the same or another db-server ?
please help me to answer this question

[ December 19, 2002: Message edited by: heiner weilandt ]
Lorus Ghut

Joined: Jul 31, 2002
Posts: 28
I have a somewhat simular simular question.
I am devloping a "small" web application, based on jsp, servlets, and a mySql database and my concerns is how to implement this application so that it will handle multiple users with good performance. My page is requested at about 3000 times a day, will I need to use a connection pool?, I develop a thread safe application i.e all users(incomming requests) will instantiate their own controller classes which connect to the database.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

(keep in mind that I'm making these numbers up as I go)
No, it isn't essential to implement Connection Pooling, you can get away without it.
Each response will be slower.
Every time you need to hit the database you create a connection. In the case of a very small query like "select password from user_table where username=?", the query takes the smallest fraction of a second to return, but it will take you orders of magnitude (.1 to .5 of a second?) to create the Connection.
If you have 1000 database hits, the database and application serevr both spend 1000 times this sitting around.
If your site is only getting 60 hits a day, you won't notice except that the pages might take .2 second longer to return, or as much as 1 second if it has 5 database hits.
The other side is that you never design a site so that it only works if no-one visits. It isn't that great an issue to manage Connections via a pool, and it's worth it just for the sake of having one less performance issue to worry about.
Kyle Brown
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
I totally disagree. I think it's nearly criminal to use connections without a pool. The reason is that programmers make mistakes. If you forget to put even ONE connection.close() statement in your code without pooling you have a mega memory leak (each connection is about 1MB, BTW). With a pooling implementation even if you forget to close the connection, it will be reaped by the pool when a timeout expires.

Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at for other WebSphere information.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Yep, I was assuming the JDBC code was correct.
But if programmers make mistakes, they can forget to return Connections to the pool. Idealy the Pool should timeout connections and recreate them, but you'd still be assuming the pool manages this correctly.
In the case where the difference between pool or no pool is only Connection re-use, ignoring other effects like programmer error, there is little immediate benefit when very few hits are made any way.
(I agree that you always use Connection Pooling where possible, just playing Devils Advocate)
I suppose another benefit to Connection Pooling is the ability to limit the limit the load on the database. This is another effect you won't encounter if you are getting 60 hits a day. :roll:
Connection Pools can grow and shrink depending on demand, so that you have spare Connections available, but you don't hold onto too many such that it becomes a resource hog. You can also set up an upper limit so that it doesn't just keep creating Connections until the whole system chokes.
Connections are database resources, not Java resources, so it makes sense to have some sort of wrapper on them to make sure they are managed in a responsible way.
It's too early in the morning. I'm rambling.
Therefore: Connection Pools are a good thing. Not using them might not kill you, but you'll never know until too late.
Manjunath Subramanian
Ranch Hand

Joined: Jul 18, 2001
Posts: 236
"each connection is about 1MB, BTW"
Just curious Kyle, How did you arrive upon that?
Ken Shamrock
Ranch Hand

Joined: Jan 23, 2002
Posts: 139
It seems that other language like asp doesn't make use of connection pool (I donno) ? If this is the case, Servlet is far more complex then other languages. ie, need to concern more things

Thanks everyone who helped me
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
come on guys, of corse you can live without the connection pooling. there are some guys out there on Vespas. you can join them or you can drive in a brand new porsche. it's just a matter of choice.

Asher Tarnopolski
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

Originally posted by David O'Meara:
The other side is that you never design a site so that it only works if no-one visits. It isn't that great an issue to manage Connections via a pool, and it's worth it just for the sake of having one less performance issue to worry about.
DC Dalton
Ranch Hand

Joined: May 28, 2001
Posts: 287
I have found that Connection Pooling, although very server friendly is NOT mandatory. Case in point...I webmaster one site on a hosting company that doesnt allow pooling (they really havent a clue) so we have to use standard connections.... the site receives approximately 2000 visitors a day & 1/2 of the site requires a connection on every servlet. On an average I would have to say each visitor creates 10 or so connections during their visit to the site.... Now I am NOT saying this is the right way to go, far from it. We are stuck with a moron hosting company that, although they offer servlets, still thinks Java is a good cup of coffee. What Im saying is that in a pinch a good Linux box / MySQL setup can withstand a lot more connections than you might think. The one absolutely VITAL thing in this situation is making sure all of your objects are closed (ResultSets, Statements & Connections!
Bruce Jin
Ranch Hand

Joined: Sep 20, 2001
Posts: 672
I don�t think JDBC is deadly. I have used it for 3 years (for local and remote database access) and never saw it brought down anything. (my win2000 crashed numerous time during this period for no reason). On the other hand any code can kill the server if not code properly.
Connection pool is very easy to code. For example, see Marty Hall�s book or web-site to download one.
I think one can do without connection pool. Make sure the connection is always close (put in finally {} for example). Each connection will cost a fraction of a second.
Sometimes connection may not be very practical to code. For example, the database may require a user ID to connect to the database. In this case the connection is user specific.

We love Java programming. It is contagious, very cool, and lot of fun. - Peter Coad, Java Design

Crazy Bikes created by m-Power
I agree. Here's the link:
subject: is jdbc connection deadly for application servers ?
It's not a secret anymore!