I wish to avoid passing the connection through the layers of the
application (from controller to DAO).
The controller initialize the connection and must pass it to the Dao
layer. I don't want to pass the datasource or connection to the business
layer as a parameter.
Futher, the data source can be different for each user : it's not
possible to use a static attribute to store the connection or the
datasource (by example, in a connection factory).
That's why I think that "threadlocal" is the solution for passing the
connection between 2 non adjacent layers : is it a bad practice?
Jean-Claude HAW-KING-CHON
*MédiFirst **
**Immeuble LE SESAME**
*8 rue Germain Soufflot
78180 Montigny le Bretonneux
*Hotline Support: 01 79 85 39 40*
Le 05/04/2013 12:40, Michael-O a écrit :
Am 2013-04-05 11:37, schrieb Jean-Claude Haw-King-Chon:
Hi,
I use the connection pool of tomcat7 and set a connection in a
ThreadLocal. The context is a web application : the threadLocal is
configured when the http request is initialized. The jdbc connection is
closed and removed from the threadLocal when the resquest is destroyed.
Why do you do that at all?
Why don't you simply use such an idiom in your thead/controller:
...
Connection conn = ConnetionUtils.getReadWriteConnection(DataSource
dataSource); // has to be implemented of course
..
Use this connetion in the entire thread, pass it along, when you are
done. Close it.
ThreadLocals are useful in other cases but not in this one.
Michael
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org