You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Jose María Zaragoza <de...@gmail.com> on 2013/04/29 15:30:56 UTC

validationQuery with Tomcat 7 JDBC Pool

Hello:

I was using validationQuery in Tomcat 6 for JNDI datasources, so to check
connections before borrowing to the caller
And, about documentacion, testOnBorrow parameter is true by default

testOnBorrow - true or false: whether a connection should be validated
using the validation query each time it is borrowed from the pool. Default:
true

http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html

And all works fine


Now , I want to use JDBC Pool with a new web application deployed on that
Tomcat 6.
So, I consider it as an standalone application, and I use
org.apache.tomcat.jdbc.pool.DataSource class ( I use Spring-MyBatis to
configure datasource , injecting it as a  bean)

I've read in Tomcat 7 JDBC pool documentation that testOnBorrow is false by
default in this case
Is it right ? Must I define testOnBorrow = true explicitly ?
It's little bit strange that default values be different either access by
JNDI or bean  instantiation

Should I use org.apache.tomcat.jdbc.pool.DataSourceFactory instead
of org.apache.tomcat.jdbc.pool.DataSource ?
My doubt is if one is better than other in performance terms

Should I use META-INF/context.xml and to use <Resource> ?

Thanks and regards

Re: validationQuery with Tomcat 7 JDBC Pool

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Jose,

On 4/29/13 9:30 AM, Jose María Zaragoza wrote:
> Now , I want to use JDBC Pool with a new web application deployed
> on that Tomcat 6. So, I consider it as an standalone application,
> and I use org.apache.tomcat.jdbc.pool.DataSource class ( I use
> Spring-MyBatis to configure datasource , injecting it as a  bean)

If you are using Spring-MyBatis to configure the DataSource, then
Tomcat has nothing to do with it (other than you are using Tomcat's
jdbc-pool as a library).

> I've read in Tomcat 7 JDBC pool documentation that testOnBorrow is
> false by default in this case Is it right ?

The default for testOnBorrow is false in all cases, including this one.

> Must I define testOnBorrow = true explicitly ?

If you want to enable testOnBorrow, then yes, you must define it
explicitly.

> It's little bit strange that default values be different either
> access by JNDI or bean  instantiation

I don't see any inconsistency. The default values are different for
Tomcat's jdbc-pool and commons-dbcp, but they are different libraries
so different defaults isn't be unexpected. Given that Tomcat's
jdbc-pool should be a drop-in replacement for commons-dbcp, I would
have expected the defaults to be the same, but in this case the
authors chose not to do this (probably to reduce the in-memory
footprint of jdbc-pool under its default configuration, because I
believe testOnBorrow is implemented as an interceptor so every object
check-out goes through another method call). Also, testOnBorrow is a
fairly wasteful configuration given that most pools have a lot of
activity. Checking a connection on a schedule is much more efficient
than testing every single check-out.

> Should I use org.apache.tomcat.jdbc.pool.DataSourceFactory instead 
> of org.apache.tomcat.jdbc.pool.DataSource ?

Why? An object of the DataSourceFactory class produces objects of the
DataSource class. I don't believe they are interchangeable.

> My doubt is if one is better than other in performance terms
> 
> Should I use META-INF/context.xml and to use <Resource> ?

If you want to use <Resource>, then don't use Spring-MyBatis to
configure the DataSource... only to inject it into your data service
objects. You'll still have to configure it /properly/, though.

- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJRfofiAAoJEBzwKT+lPKRYaNwQAKUNqTTgp0ivZhz2j4af2MHD
xlTr8cNAUl0jSLHJFQuagMVFHLt9pPsLvaWxfx+NCOS/jgPb5dQcmoWPXW/hw1MR
xvIL45CmF8DUoo3Cl1f36ajCqpkxm40aYWJ7D1czc2vysr+9OAno8ZGPt9vG4Llb
lNps2nyGmt1CtXWLQwL2kiBuYruZ6GEE47aVNESBQ4q3FiPNoX1emVBbBCNBSGi0
mlsCh4gNnfcTtvbj+3RQBPXSfXUVE/uf8t1c7c4w1UDkrt3LcLRKjtQchSRSy/tU
bHc70nw8XsQPax9SalxIY2vmfy0/adQAuH+gTqdCt9e4G2HihGGYl3Od83Goh0Z3
Rm5VK+e4WWqKxUpreVBgz14farB2zCOnKbDlEm7TGLUrm4ebMEMBhbHAqYGsG5/P
bfsce9La8U15fY6HAepqAtAGVt1xwUwOgQ0E1y3G2LJ5l9vLw5jsltpzC7sF760c
M+a7HMYU9PEfw/xcmWgkRtap6skE7RGwnteI864en7lM3DYusxAVHFwptu9FYW3t
eucWd7BT6l7EfmEVf5/K+tBKJld9irUP/iOcL9Cndf8uz05oFo8QyxLtHlVzkw5k
v4MCjZQi9hP8vkGfAAW/N9pN/mommEVMtLvGB2M011kRsp+1kRitjqJWChKpuD2v
S8g0n6RQuGyvvBaI6EaT
=axfr
-----END PGP SIGNATURE-----

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