Connection Pool in Application server uses Prototype Pattern?
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Parag_Bharambe
Posted On:   Wednesday, November 6, 2002 04:21 AM

Hi , Application server provider implements Connection Pooling. I could see it can be done in two ways(Assume there is connection pool of 5 Connection) 1 Create Connection explicitely using JBDC each time(5 times) creating Connection Object . 2 Create one Connection Object and clone it number of times(5 times). I think second approach is more appropriate. Creating a connection involves considerable amount of work and time. In case of first approach there would be lot of work to be done although repeatedly. In second case the object once crated, will be replicated to new Objects. Thus save lot of object construction work    More>>

Hi ,


Application server provider implements Connection Pooling. I could see it can be done in two ways(Assume there is connection pool of 5 Connection)



1 Create Connection explicitely using JBDC each time(5 times) creating Connection Object .



2 Create one Connection Object and clone it number of times(5 times).



I think second approach is more appropriate. Creating a connection involves considerable amount of work and time.



In case of first approach there would be lot of work to be done although repeatedly.



In second case the object once crated, will be replicated to new Objects. Thus save lot of object construction work is saved.


Please let me know if if you have another point.


Parag

   <<Less

Re: Connection Pool in Application server uses Prototype Pattern?

Posted By:   Joe_Felchlin  
Posted On:   Friday, December 6, 2002 01:40 AM

A Prototype pattern really doesn't save object contruction cost. You will normally have to create a new copy of the object in the clone operation anyway. The purpose of a Prototype may be slightly different than what you had in mind.

In any case, the JDBC connection may be several SECONDS, dwarfing the cost of object construction however you do it. I would recommend the first approach, since you want to get independent connections. If you are cloning, internal state may remain unintentionally duplicated, and you may not wind up with two truly independent connections. You can still get an optimization, but in a different way.

A connection pool is a repository for open connections. The work of opening a connection and storing it in the pool is done at some point before the connection is actually needed or used (and could even happen in a different Thread or process). Clients share connections by checking each connections out, using it, and returning it (checking it back in after finishing) when they are done with it.

Thus, to clone or to construct is not really at issue for performance reasons.

Re: Connection Pool in Application server uses Prototype Pattern?

Posted By:   Christopher_Koenigsberg  
Posted On:   Wednesday, November 6, 2002 07:35 AM

If you expect 5 clients to use 5 (virtual) connections at once, doing 5 different things with them, then you better have 5 real (physical) connections created for them, using JDBC each time.



The connection pool's usefulness comes when you have 10 clients, and you maintain 5 real (physical) connections, so the 10 clients can get one (virtual) quickly from you when they need it, without having to wait for the actual (physical) JDBC connection creation each time (as long as no more than 5 of the clients want a connection at the same time).

About | Sitemap | Contact