-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Neven,

On 3/5/14, 8:25 PM, Neven Cvetkovic wrote:
> 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.

The connection pool does not "run in the background". The code
executes when a request-processing thread requests a connection.
Threads execute code. Code doesn't execute or "run" itself.

> 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.

There are such threads, if you configure them.

>> 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...

In the threading world, "synchronization" and "serialization"
essentially mean the same thing: protected and exclusive access to a
particular resource. Presumably, the OP wanted to know whether it was
safe to use a connection pool in a multi-threaded setting, but it
wasn't clear if he meant the connection pool itself, or an individual
connection obtained from the pool. That's why I asked.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJTGfIPAAoJEBzwKT+lPKRYRuIP/2/Dd4dZtUy4/NUomnxsTQB3
PnTiq4wPcun8+iF4pIF6QAmyQImhVcfqhp/PhpenR3LrH/B0nPooV5XO5zBsgzQB
r6TY81895MHCU6ICLsSDItAwvESRrtlj3k2cHfNXwankhePjAHgpfbS7pyn7FFiL
15ItenAG1zQDXpfPEEcHq/q1oF42s+GRRwVqN+LNCG9WP6eI5+nnMTvRhyE3aprc
g98EdfI852svQK+dAE4S3kN3HxE5nfjEk0m0paDZLl4nWCbAs6PfgIjsRe+YV/hO
MEaONNIGFtHk/wvmAzB12xXLm0y/XH9QF8uv/JNr/ZdPbFq1OOPaRY+7IPZEZkxa
itYe5lEKpyH+xZFSStAD6UPmdzenYpDbrsUEZgMbVVhnSnrrS/VkcRDk+P3lsPui
j1MW5Lt1YyJnweNio3w8NQN5VX8CZm1CjqLMqcVX05qSj+pysX+siKTxAXOUydzG
Qg1Yu3XL598O+9aETCybYbFf9bM6UuYsbVG879sDyt3EJVxu6TKwEYi5JH9fKME3
Sl/kdFCY4+6XwQ5yhlwVhAgPV6BF1GP9LGPtKkwvrUxtv75o+WtXLzTEYf/WAOA/
Mk+kXXuYFA2sfrUl096G06Y3mipwfxwmKG9WX55TtIDDgd9zzzVNFm4T0V+1QQHV
nXQ6lCWO4nUKTZLOKdQD
=yFSO
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to