On Wed, Mar 5, 2014 at 3:15 PM, S Ahmed <sahmed1...@gmail.com> wrote:

> Hi,
>
> With jdbc pool, is each socket connection in the pool handled by a separate
> thread?
>
>
Ahmed, thanks for asking this question - it is sometimes very confusing
with all different kind of pools: connection pools, threadpools, etc...

Chris pointed out already - the connection pool does not have any
threads... It is not a process that runs in the background, these are just
connection objects that are sitting in memory.

Threads are created by the Tomcat container (executor) once the connection
is received by the Connector. The created thread is then going to be
handled by the container and it will go through the stack call, through
Valves, Filters, Servlets, your middleware layer, DAOs, JDBC/JPA calls and
then finally through your datasource object, connection, PreparedStatement,
ResultSet, etc... and back all the way to the socket that browser
initiated, returning the thread to the threadpool (e.g. http-bio-8080).

Now, I am not sure about the connection pool implementation details, how
connection pool keeps connections open, if there are any background threads
that are handling connection management (closing abandoned connections,
opening new connections as the demand rises, etc...)

Maybe someone can comment on that.



> Say you have 20 connections set to be open at minimum, does that mean there
> will be 20 threads?  If not, then there is a degree of serialization then
> right?
>


Well, there will be no serialization, but rather "synchronization" as there
are at most XXXX available connections, if the connection pool (datasource)
reaches maximum allowed connections, depending on the implementation - it
would be a blocking call, until the pool has available connection to
provide...

Look at the documentation for Tomcat default connection pool implementation:
https://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html


Hopefully that clears some of the confusion.


Cheers!
Neven

Reply via email to