• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Where to release database connection before servlet gets destroyed?

 
Shrikant Deshpande
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Manish Singh
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic