wood burning stoves 2.0*
The moose likes Servlets and the fly likes  Where to release database connection before servlet  gets  destroyed? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark " Where to release database connection before servlet  gets  destroyed?" Watch " Where to release database connection before servlet  gets  destroyed?" New topic
Author

Where to release database connection before servlet gets destroyed?

Shrikant Deshpande
Greenhorn

Joined: May 17, 2010
Posts: 15
If I have database connection in my servlet.

Can only one database connection in init() method will handle multiple client request?

Where to release that connection before servlet gets destroyed.(Unloaded from memory.) ?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I wouldn't keep a database connection in a servlet. At best it would become that servlet's performance bottleneck.
You're more likely to run into other issues that would be worse.

Look into container managed connection pools.
It's the standard and a much better way to go.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Manish Singh
Ranch Hand

Joined: Jan 26, 2007
Posts: 160
Connection should always be get and returned to the connection pool as it has many advantages.

And connection should be returned to the pool as soon as you don't need that. Keeping connection in servlet is bad
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Where to release database connection before servlet gets destroyed?