Re: Connection Pool in Application server uses Prototype Pattern?
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.