You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by S Ahmed <sa...@gmail.com> on 2014/03/05 21:15:06 UTC
understanding jdbc pool
Hi,
With jdbc pool, is each socket connection in the pool handled by a separate
thread?
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?
Re: understanding jdbc pool
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Martin,
On 3/6/14, 7:53 AM, Martin Gainty wrote:
>
>
>
>
>> From: neven.cvetkovic@gmail.com Date: Wed, 5 Mar 2014 20:25:36
>> -0500 Subject: Re: understanding jdbc pool To:
>> users@tomcat.apache.org
>>
>> On Wed, Mar 5, 2014 at 3:15 PM, S Ahmed <sa...@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.
> MG>Not from 1.4 commons-dbcp..here is a typical reference to Thread
> in source MG>Thread.currentThread(). MG>(Although I have seen
> multiple thread calls in attached testcases) I have not seen
> Separate Thread in main body MG>I am sure someone here would put a
> feature request in to support Thread-Aware Connections MG>If you
> put the feature request in I will second the request (and make sure
> ThreadAware gets implemented)
What in the world are you talking about? Why would any particular bit
of code need to be "aware" of the thread that is executing it? There
is no ThreadAware interface AFAIK. If there were, what would it look like?
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBCAAGBQJTGfJ5AAoJEBzwKT+lPKRYNRwP/RZhZDGhrZ/tzzAifd3XFn0G
f8p3b5gx2c2+cFrdeDPAVM/l/2w4mZ5YfqCYVKqkRh7qH6+abxAC9GzVh6QqOGVG
LR1SMKBd2QtnSxZrKCJhuk/y658hMYdRyAmRuIJvqUXm4h1biYS5ivYBNnncESq4
RQNbJIi4beSXMlg05/bHSU3bS/SXANBfMGXXPR7hMoyhhkOSXbBtxHu0o/JzDxq6
9kJV/V3OG1vhLLNkHVtW4MN8WIXg0+L9b+6zsghKMollKh11yrfEvQKY92hyPy0S
f1WNgMOFUvXmHk3WcJqKBS99kijVI2Q26L26/B2mJKk4c0ETwYHmq+StjjX3AC8g
UaorwVxloGAr1BH72AqUFSHE4EOSK8lXEseyz11dI5nR2za2nSaaCZehD0BhmYhS
dTJNxYlWrBsBCbyPllhGHztTSVRPpDUAiB7P896mK1daOpkg6TIruB/vt+IUeDTb
RDKnMDCgaqJdkVOgwhbErKJrqStT0wv1Wt8Rn+6hsur02YHEf7Z0K0ITwanQvoyu
gCrnxi7zSDJDTNG3eiRMzfYus5wmaZZvk4gX+fZhSWEx/ZnTOU189UZ2WFpii7jq
oXA9AWtUN4HI7+/qCvzm6gXPn8aGqsg7ptEkxTmq2y6KgXE41alq4d+Cq+2lFIl/
SskaaMjyla9e4JdjuoQs
=PK1X
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: understanding jdbc pool
Posted by Martin Gainty <mg...@hotmail.com>.
> From: neven.cvetkovic@gmail.com
> Date: Wed, 5 Mar 2014 20:25:36 -0500
> Subject: Re: understanding jdbc pool
> To: users@tomcat.apache.org
>
> On Wed, Mar 5, 2014 at 3:15 PM, S Ahmed <sa...@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.
MG>Not from 1.4 commons-dbcp..here is a typical reference to Thread in source
MG>Thread.currentThread().
MG>(Although I have seen multiple thread calls in attached testcases) I have not seen Separate Thread in main body
MG>I am sure someone here would put a feature request in to support Thread-Aware Connections
MG>If you put the feature request in I will second the request (and make sure ThreadAware gets implemented)
MG>Then again Im sure there are other libraries that will handle Thread aware database connection pools
MG>would anyone know the names of those libraries?
MG>BTW Mr Schultz is right
>
> > 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
Re: understanding jdbc pool
Posted by Neven Cvetkovic <ne...@gmail.com>.
On Fri, Mar 7, 2014 at 11:21 AM, Christopher Schultz <
chris@christopherschultz.net> wrote:
>
> Neven,
>
> On 3/5/14, 8:25 PM, Neven Cvetkovic wrote:
> > On Wed, Mar 5, 2014 at 3:15 PM, S Ahmed <sa...@gmail.com>
> >>
> > 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.
>
> +1
Chris, thanks for the clarification. That's what I meant (/said) - the
connection pool is NOT a process, but code (object in memory) that gets
executed by the request-processing thread.
:)
Re: understanding jdbc pool
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----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 <sa...@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-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: understanding jdbc pool
Posted by Neven Cvetkovic <ne...@gmail.com>.
On Wed, Mar 5, 2014 at 3:15 PM, S Ahmed <sa...@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
Re: understanding jdbc pool
Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Ahmed,
On 3/5/14, 3:15 PM, S Ahmed wrote:
> With jdbc pool, is each socket connection in the pool handled by a
> separate thread?
Why would a JDBC connection need a thread?
> Say you have 20 connections set to be open at minimum, does that
> mean there will be 20 threads?
No.
> If not, then there is a degree of serialization then right?
Serialization of what?
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iQIcBAEBCAAGBQJTF5ooAAoJEBzwKT+lPKRYsYMP/ixF132G84VhwCGrO980XZH3
tGs5kt4rihKCK43vKviyXrpTJIhBMuvJkdinhXFeZ5ZtRUv0AyudAPUT0o8QRXwA
rpGIR+BQPZivmB39h0Er+YwGL+uB06lspJKCFr8ARq4IwMLUQEaDdjxirh6lGOBB
1CIz6qvZoNop6ZGtYQdtGbVP5GmGpPEz609Q3q9KIZ7gIk98bKiLIN+RmzyfdaGk
0nA4qYETwQQnZ+ymZ4lDKC6G3D2Q8+x3eJWQRVd8fQdaspAnU/zkA7I3Eb8jnRoq
HU1VaUVtFeY8Z8hkHnVrwumXQtMUG7qArc6BZXKC99eOvl+0LQpxHeE/afza1SfT
zpxmRCL8YSNMTw+W0Tgmjn2JvoOak+rGSM8yW+/LRYNdgNPt/Y0md+Vt6lv/c8kC
Dyy3vyTnG0D73U5yZSuzyJX69h2Lj//bKcOkcWRdsIE8J1/borlyVJbgiSJjNdnk
MJdPf0VmAqUeOloYyrQLrmeuQXiCnaYPgizOyGLa9FxW5sHrXAwRB9wUkyCu62gV
A6hRNZUv9t09N55ZstPzp4JY7d2fFCj7w6PRFJktCqbHQZnw56WXAmjUwQo9R7xU
0fiHfR4YaoW3Yzvha/H46OJ2E1ExoKP5+2SopBqkKdXRBzfeQ3DLypZ/t+5sFXYp
kAbkUjx4j6GKXuvi8TQB
=TGE9
-----END PGP SIGNATURE-----
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org