You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dale Ogilvie <Da...@trimble.com> on 2011/05/11 01:24:17 UTC

How to close all connections in a Tomcat container db connection pool?

Hi,

We just had an issue in production on tomcat 6, a web application was
getting strange errors from the oracle database:

java.sql.SQLException: ORA-06508: PL/SQL: could not find program unit
being called in Package

Our configuration uses a database pool in GlobalNamingResources of
server.xml

  <!-- Global JNDI resources
       Documentation at /docs/jndi-resources-howto.html
  -->
  <GlobalNamingResources>
    <Resource accessToUnderlyingConnectionAllowed="true"
auth="Container" driverClassName="oracle.jdbc.OracleDriver"
maxActive="10" maxIdle="5" maxWait="10000" name="jdbc/oraclePool"
password="xxx" type="javax.sql.DataSource"
url="jdbc:oracle:thin:@db.acme.com:1521:ACME" username="java_pool"
validationQuery="select 1 from dual"/>
  </GlobalNamingResources>

The cause of the error was the db admin patching a db package underlying
one used by our web-app. Post patch all the packages appeared valid to
the admin, but not to our app using db connections established prior to
the db patching.

We redeployed our app, but the error persisted. The only way to remove
the db error was to restart tomcat. Possibly, there was something wrong
with the database connections in the pool, not reflecting the new state
of the database.

Is there any way to tell the running Tomcat to clean out the connection
pool, so that it throws away all the established connections, and
establishes new ones for the applications. I don't really want to have
to stop all the applications on our server to deal with this sort of
issue.

Thanks

Dale

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


RE: How to close all connections in a Tomcat container db connection pool?

Posted by Dale Ogilvie <Da...@trimble.com>.
Thanks Chris. Not as simple as I'd hoped, about as complicated as I expected :-) 

-----Original Message-----
From: Christopher Schultz [mailto:chris@christopherschultz.net] 
Sent: Thursday, 12 May 2011 1:56 a.m.
To: Tomcat Users List
Subject: Re: How to close all connections in a Tomcat container db connection pool?

Hope that helps,
- -chris


Re: How to close all connections in a Tomcat container db connection pool?

Posted by Filip Hanik - Dev Lists <de...@hanik.com>.
in Tomcat 7 (not sure if backported to 6), you configure a

<Resource
   ....
   closeMethod="close"
   ....

/>

Filip



On 5/11/2011 7:55 AM, Christopher Schultz wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Dale,
>
> On 5/10/2011 7:24 PM, Dale Ogilvie wrote:
>> The cause of the error was the db admin patching a db package underlying
>> one used by our web-app. Post patch all the packages appeared valid to
>> the admin, but not to our app using db connections established prior to
>> the db patching.
> Looks like the Oracle connection caches some of that metadata. Maybe
> your dba shouldn't mess with that kind of stuff while the application is
> running :)
>
>> Is there any way to tell the running Tomcat to clean out the connection
>> pool, so that it throws away all the established connections, and
>> establishes new ones for the applications. I don't really want to have
>> to stop all the applications on our server to deal with this sort of
>> issue.
> You'll have to basically reach-into the JNDI context, pull-out the
> DataSource object, cross your fingers and cast it to some "known" object
> type (like org.apache.tomcat.dbcp.dbcp.BasicDataSource) and then call
> methods on that Tomcat-specific class.
>
> You could call the "close" method on that class, but I suspect you'll
> end up with an empty, useless pool at that point. It's possible that the
> pool will re-initialize itself when you call getConnection but you'll
> have to check that out for yourself.
>
> You could also look into using JMX, but you'll have to poke around
> looking for the key for your DataSource and then I don't have any idea
> what actions are available... YMMV.
>
> Maybe there's a method on the Oracle-specific connection object(s) that
> you can use to flush all the metadata. You might want to look into that,
> too.
>
> Finally, if you use a webapp-specific DataSource (that is, not a
> "global" one) and you properly close the DataSource when the webapp
> shuts down, a new one should be created for your when the new instance
> of the webapp launches.
>
> Hope that helps,
> - -chris
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (MingW32)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk3KlV8ACgkQ9CaO5/Lv0PCLcQCgt5X+2GBrQpIaHSY+nYwFZZrp
> QsYAnjQTGHKiwGNTrdkBkRkHbwPebosE
> =Z1eH
> -----END PGP SIGNATURE-----
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
> -----
> No virus found in this message.
> Checked by AVG - www.avg.com
> Version: 10.0.1321 / Virus Database: 1500/3629 - Release Date: 05/10/11
>
>


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


Re: How to close all connections in a Tomcat container db connection pool?

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

Dale,

On 5/10/2011 7:24 PM, Dale Ogilvie wrote:
> The cause of the error was the db admin patching a db package underlying
> one used by our web-app. Post patch all the packages appeared valid to
> the admin, but not to our app using db connections established prior to
> the db patching.

Looks like the Oracle connection caches some of that metadata. Maybe
your dba shouldn't mess with that kind of stuff while the application is
running :)

> Is there any way to tell the running Tomcat to clean out the connection
> pool, so that it throws away all the established connections, and
> establishes new ones for the applications. I don't really want to have
> to stop all the applications on our server to deal with this sort of
> issue.

You'll have to basically reach-into the JNDI context, pull-out the
DataSource object, cross your fingers and cast it to some "known" object
type (like org.apache.tomcat.dbcp.dbcp.BasicDataSource) and then call
methods on that Tomcat-specific class.

You could call the "close" method on that class, but I suspect you'll
end up with an empty, useless pool at that point. It's possible that the
pool will re-initialize itself when you call getConnection but you'll
have to check that out for yourself.

You could also look into using JMX, but you'll have to poke around
looking for the key for your DataSource and then I don't have any idea
what actions are available... YMMV.

Maybe there's a method on the Oracle-specific connection object(s) that
you can use to flush all the metadata. You might want to look into that,
too.

Finally, if you use a webapp-specific DataSource (that is, not a
"global" one) and you properly close the DataSource when the webapp
shuts down, a new one should be created for your when the new instance
of the webapp launches.

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk3KlV8ACgkQ9CaO5/Lv0PCLcQCgt5X+2GBrQpIaHSY+nYwFZZrp
QsYAnjQTGHKiwGNTrdkBkRkHbwPebosE
=Z1eH
-----END PGP SIGNATURE-----

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