Solved

connecting pool and session

Posted on 2004-10-01
1
192 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
web service Rest Client creation 4 102
love6 challenge java 31 133
Can't access image with tomcat/html 6 114
glassfish admin console 1 47
When using a search centre, I'm going to show you how to configure Sharepoint's search to only return results from the current site collection. Very useful when using Office 365 with multiple site collections.
Invest in your employees with these five simple steps to improve employee engagement and retention.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the adminiā€¦

734 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