• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Connection pooling design pattern

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which design pattern is generally used for connection pooling?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused - why do you want to know???
 
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean to use a connection pool, or to implement a connection pool?

From a user's point of view, a connection pool is just a resource factory. If you're implementing on, it's pretty much based on what mechanisms you want/need to employ. Provided that to the consumer you're a connection factory.!
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's just say "design" rather than "pattern". Pools may be common enough to be patterns, but I'm not sure I've seen them in full-blown pattern language.

I've seen a couple approaches to connection pools. One makes all users aware they are using a pool. I like this because it's simple even though it impacts the client. You can use a generic off-the-shelf object pool:

The other approach hides the pooling. I'm not sure how they get connections; I used snipped ConnectionManager from a toy project.

This is a lot more work as you have to extend or wrap Connection to return to the pool instead of really closing and much more.

Does that much track to your line of questioning? There's more to talk about ... policies for growing and shrinking the pool, detecting stale connections, etc.
 
Ilja Preuss
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Stan James:
The other approach hides the pooling. I'm not sure how they get connections; I used snipped ConnectionManager from a toy project.

This is a lot more work as you have to extend or wrap Connection to return to the pool instead of really closing and much more.



That's the Proxy design pattern. It's how the Jakarta Commons connection pool is implemented, for example. And it's not even that hard, if you know how to use Java's dynamic proxies...
 
Tim Holloway
Saloon Keeper
Posts: 27764
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Technically, the connection manager is, like I said, a factory. The "connection" you get back is, however a proxy for the real connection. Done that way so that the proxy connection close() method will simply return the proxied connection back to the pool instead of destroying it.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Connection pooling (in the context of 'connection' referring to a connection to a service type such as database etc.) is specialization of object-pool pattern, a creational design pattern

An Object Pool manages the reuse of objects for a type of object that is expensive to create or only a limited number of a kind of object can be created. These instances of a class can be used interchangeably.

This can be used inconjunction with Factory-Method, Singleton and cache-management patterns.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic