Solved

connecting pool and session

Posted on 2004-10-01
1
193 Views
Last Modified: 2010-04-01
is it a good idea to save the db connection getting from the pool in the session? I have a servlet that does not work well:
1) the servlet get the db-conn from the pool then put it in the session: with doing so, it enables other beans making use of the db-conn
2) the db-conn is bieng closed at the and of the session

please ..ideas

thanks


0
Comment
Question by:aimueller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 7

Accepted Solution

by:
lhankins earned 50 total points
ID: 12212440
Storing the connection in the session is a bad idea...

First, connections are not serializable (only things which are serializable should be put in the session).   The servlet container can serialize sessions out to disk at any time (and in scenarios where you're doing clustering, objects in the session may be replicated to other members of the cluster).

Second - the whole idea of  a JDBC connection pool is to use a smaller number of connections to service a larger number of users.   For example, you may have a connection pool of size 100, that you use to service a concurrent user population of size 200.      For this to work, you should grab a connection from the Connection pool, do something with it, then "close" the connection (which doesn't really close it, just sticks it back in the pool).

For pure webapps, you can grab a connection at the beginning of a request, and close it once you're done servicing the request.    One common way to do this in a pure webapp is to implement your own ServletRequestFilter (grab connection just before starting the request, close it at the end).   If you're using struts, you could also add your own BaseAction class which does this sort of thing (and exposes it to all concrete descendants).  

Here's an example of how to do something similar with a Hibernate Session object (a Hibernate Session is analagous to a JDBC Connection - in fact, it wraps a JDBC Connection):

http://www.hibernate.org/43.html
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question