Solved

connecting pool and session

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

In this article, you will read about the trends across the human resources departments for the upcoming year. Some of them include improving employee experience, adopting new technologies, using HR software to its full extent, and integrating artifi…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now