File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes connection pooling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of RabbitMQ in Depth this week in the Open Source forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "connection pooling" Watch "connection pooling" New topic

connection pooling

Louis Tangolin

Joined: Nov 13, 2004
Posts: 8
I have following questions about connection pooling ---

1. if the server sets an initial connection number as 10 in the pool, then what if there are 11 requests coming in, each needs a connection ? Certainly the first 10 requests will use the 10 connections in the pool, then how about the 11th request ? When it finds that the 10 connection are all being used, does it need to wait until one of the 10 requests is done and returns the connection back to pool ? or, will the server automatically create a separate new connection for this 11th request ?

2. after a request finishes using the connection and returns it to pool, will the server keep this connection forever (as long as the server is alive) in the pool so that it can be used by any new request ? or will the server kills the connection after the connection is idle for a certainly amount of time ?
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
this question deserve a detailed answer. hmmmmm

- the connection pool always have some no of connections, always. as you mentioned it 10. you can say it as initial size.

- if all connection are in use by a no of requests, then there is a mechanism which will increase the pool with an extent, say 5. it means if all connection objects are busy the pool definitely increase but by 5 because if it increase just by 1 then there would be a definite chance to make another connection soon. thus it will make 5 connections when increase. and so on.

- but again there would be a maxsize defined, say 30 then if the pool size is already 30 then the new request must wait for sometime.

- after getting some no of connections back it will destroy some connection objects which were made on need basis. say there is 10 objects in the pool all gets busy. on new request the pool increases by 5. now there is 15 no of connections. say 12 is in use and 3 are there for coming requests. but no request are made and 8 connections are back. then it will destroy 5 connections which were made on need basis and still have 6 there in the pool. and if the remaining connection would come be back then it would gain all 10 connections which was the starting no.

- yes, pool should takecare about the stale connections. it can handle it by some mechanism.

i tried my best to give you the idea. please appreciate

Loren Rosen
Ranch Hand

Joined: Feb 12, 2003
Posts: 156
The only thing that needs adding is that the details can vary from pool implementation to implementation. Some might even give you a choice of different policies.
I agree. Here's the link:
subject: connection pooling