On 17/05/2013 15:34, Jeffrey Janner wrote:

> Michael and Mark - I happened to be reviewing how Oracle handles
> QueryTimeout yesterday on an unrelated issue and came across a
> passage in the JDBC Developers Guide (11g) that covered this
> Monitoring Thread (page E-3). My reading of it was that Oracle
> creates a single monitoring thread per JVM, so if there are multiple
> apps utilizing the Oracle driver, you certainly don't want one app
> shutting down and taking the monitor thread with it. I'm sure this
> one of the reasons that Mark says that the monitor thread should use
> the parent class loader.  Oracle should probably consider this. My
> question though is how is all this affected when the jdbc library is
> loaded on a per-app basis, i.e., it's not shared but loaded from each
> app's WEB-INF/lib folder?  Should the app then unload the driver when
> it shuts down to avoid memory leaks?  Or is there a special process
> that needs to be followed? Jeff

If the driver is in WEB-INF/lib things get really messy, very quickly.
You can make it work if only that application is using the driver (you
have to make sure you manually deregister the driver in a
ServletContextListener). If multiple apps try and use it, or if multiple
apps ship the same Driver, bad things happen.

There are multiple problems:

1. Using a driver automatically adds it to the DriverManager.
DriverManager is a JVM singleton. It maintains a list of loaded drivers
but does not key this list by class loader so there can only ever be one
instance of a Driver loaded even if different web applications ship
different versions of the same Driver.

2. If web app A loads the Driver and web app B tries to use it the
chances of a CNFE or similar are fairly high. You might get away with
it. You probably won't.

3. If webapp A loads the driver, webapp B manages to use it and then
webapp A is undeployed, assuming webapp A does the right thing and
deregisaters it,  webapp A will pull the driver out from underneath
webapp B.

Generally, putting it in CATALINA_HOME/lib is better. That also means
Tomcat can provide database connection pooling.

DriverManager is just one of the many JRE classes that make no
allowances for running in the class loader environments you get in J2EE
containers. LogManager is another.

Mark

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

Reply via email to