Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

temporary Connection or connection pool?

 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in a DAO, we keep a connection open through out an instance or we only get a
connection and close it in a data access method? Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34413
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Damu,
If there is more than user user, a connection pool is usually best.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks,Jeanne.

Say, in a web application (no EJB layer), for MVC model, the controller(filter or servlet) will delegate the requests to corresponding model, and the model will do the business, like getting the date from database, then, my question is:

Where should we keep the connection pool? in controller or in model.

If we keep the connection pool in controller, I think it might be easy to manage all the connection in one class(not sure). but we have to pass the connection reference to the model. this seems violating the isolation.
[ March 20, 2007: Message edited by: damu liu ]
 
Daniel Dalton
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
most servers will actually support connection pooling themselves. You should look into your particular servers details to find out how it is set up. Your web app would then access a connection via a JNDI lookup. Certainly you can do this in the Sun One webserver. I'm 99.9% certain that you can do it in tomcat by fiddling with the xml config files - though I've never done it.

Hope that helps,
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34413
346
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by damu liu:
Where should we keep the connection pool? in controller or in model.

Neither. You should keep it in the connection pool. If you server supports datasources, the server takes care of it as Daniel described. If not, you can use an open source connection pool like DBCP.

Either way, you request the connection from the pool in your data access code. It goes where you would have asked DriverManager for a connection if you weren't using pooling - in your data access class. While the connection pool is called from your model, technically it isn't in your model. And it certainly isn't in the controller - the controller should just be delegating requests.
 
Bigwood Liu
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Daniel and Jeanne.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic