Am 2018-09-11 um 23:53 schrieb Christopher Schultz:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Michael,

On 9/11/18 3:33 PM, Michael Osipov wrote:
in bug 62670 [1] -- contrary to my statement -- Mark pointed out
that is it pefectly legal to have a JDBC driver in WEB-INF/lib.
While I was living for years with the assumption that this is
discouraged because the DriverManager is VM wide and not
classloader-wide, plus numerous SO questions have been asked about
this.

Most answers are based upon speculation and age-old wisdom about
decades-old versions of Tomcat. Most of those questions haven't been
answered by anyone who actually knows the answers.

While reading [2] it is still not clear why this is a perfectly
legal case.

Putting a JDBC library into WEB-INF/lib is a supported use-case in
Tomcat, full stop. That's why it's a legal case: simply because we say
it is.

How can we improve the docs to make it crystal clear for users
under which circumstances a driver is valid in WEB-INF/lib?

I can't imagine a case where it should *not* be valid.

The documentation[2] simply says that the application won't be able to
rely on auto-registration of JDBC drivers (which has, in my
experience, always been flaky anyway) and you'll have to go back to
the practice of calling Class.forName(driverName) and possibly calling
newInstance() on the Class object, just like it was still 1995.

I haven't checked, but presumably both of the JDBC pools shipped with
Tomcat perform this operation for you, so you don't have to have a
ServletContextListener that does it, but you will want to take care to
de-register your JDBC driver when your application shuts-down, or you
will have a ClassLoader-pinning leak (DriverManager[app CL] -> JDBC
Driver Class [webapp CL] -> webapp CL -> all classes loaded for the
webapp).

There are some drivers (notably MySQL's Connector/J) that are
notoriously difficult to kill because they are written by people who
don't understand why drivers would ever have to be removed from
memory, but that's a different problem.

At $work, we still use CATALINA_BASE/lib for out JDBC drivers, but
that's simply due to historical deployment strategy.

- -chris

References left in-tact:
[1] https://bz.apache.org/bugzilla/show_bug.cgi?id=62670#c2 [2]
http://tomcat.apache.org/tomcat-9.0-doc/jndi-datasource-examples-howto
.html

Thank you very much for your elaboration. I will keep this as a reference. It still makes sense to put the driver into CATALINA_HOME/lib if you multiple apps running with the same database type.

Regards,

Michael

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

Reply via email to