1

I'm running Tomcat 7 with Apache 2.4 on Postgres 9.3 on Ubuntu 16.04 to serve a webapp. The webapp was originally written for Tomcat 5 or earlier.

I'm trying to understand a memory error using this ServerFault answer. It's filled with concepts and phrases that I don't understand, however, so I'm trying to piece it all together.

What I'm stuck on now is figuring out what database connection pool I'm using. It isn't obvious from any of the config files I've looked at, including /etc/tomcat7/server.xml and /etc/tomcat7/web.xml. How can I find what connection pool is being used and where its configuration is?

fuero
  • 9,413
  • 1
  • 35
  • 40
PiotrChernin
  • 113
  • 4

1 Answers1

0

Another Update:

The distro vendors tend to break up packages like tomcat to consolidate shared dependencies between the various packages in their lineup. That's the case with tomcat 7 as well.

To illustrate:

# apt install -y tomcat7
The following NEW packages will be installed:
[...]
  libcommons-collections3-java libcommons-dbcp-java libcommons-pool-java
[...]
  tomcat7-common
[...]

After installing, check out the package contents:

# dpkg -L tomcat7-common | grep dbcp
/usr/share/tomcat7/lib/commons-dbcp.jar
# ls -lhA /usr/share/tomcat7/lib/commons-dbcp.jar
lrwxrwxrwx 1 root root 27 Oct 10  2018 /usr/share/tomcat7/lib/commons-dbcp.jar -> ../../java/commons-dbcp.jar
# grep lib /etc/tomcat7/catalina.properties 
common.loader=${catalina.base}/lib,${catalina.base}/lib/*.jar,${catalina.home}/lib,${catalina.home}/lib/*.jar,${catalina.home}/common/classes,${catalina.home}/common/*.jar

catalina.properties controls how Tomcat's classpath should be setup when starting the server.

Update:

Quoting the docs:

The default database connection pool implementation in Apache Tomcat relies on the libraries from the Apache Commons project. The following libraries are used:

Commons DBCP 1.x
Commons Pool 1.x

These libraries are located in a single JAR at $CATALINA_HOME/lib/tomcat-dbcp.jar. However, only the classes needed for connection pooling have been included, and the packages have been renamed to avoid interfering with applications.

Still, I strongly recommend reading the intro to Java (EE) web applications listed below. If you use Java servlet containers these principles still hold, especially in the enterprise world.

For a more modern take on Java in the container world I recommend Cloud Native Java, but beware, the authors have swallowed the cloud gospel hook, line and sinker :-)

Original response:

Please clarify, are you talking about:

  • Which of the connections set up in Tomcat's configs is used by the app?
  • Where the DB connection defined and used is magically coming from?
  • Which connection pool implementation is in use?

What might be helpful is what is in the config files you mention that differs from what the OS vendor (Debian) put in them.

A broad tip I can give you is to familiarize yourself with the way deployment descriptors in Java (EE) Webapps work and how vendor-specific extensions are used.

fuero
  • 9,413
  • 1
  • 35
  • 40
  • I think I'm asking "Which connection pool implementation is in use?". I'll work on comparing config files. – PiotrChernin Jul 03 '19 at 13:07
  • This should help then: https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html#Database_Connection_Pool_(DBCP_1.x)_Configurations – fuero Jul 03 '19 at 13:22
  • I've read the linked page multiple times in the past day or so. If it helps answer my question, I don't understand how. I apologize for being obtuse, but I need an expert to spell this out for me. – PiotrChernin Jul 03 '19 at 13:31
  • I'd never heard of JNDI before the first time I was referred to the [docs page](https://tomcat.apache.org/tomcat-7.0-doc/jndi-datasource-examples-howto.html#Database_Connection_Pool_(DBCP_1.x)_Configurations) you linked, in fact. Reading about it now in [this question](https://stackoverflow.com/questions/4365621/what-is-jndi-what-is-its-basic-use-when-is-it-used), I'm not even sure we use JNDI. We use a properties file to handle the functions described. – PiotrChernin Jul 03 '19 at 13:49
  • Thank you for elaborating your answer! I appreciate your time. I still don't see how this answers my question, however. I don't have a file `tomcat-dbcp.jar` in my system. Even if I did, the presence of a `.jar` doesn't imply that that package is used by Tomcat. Surely there's a configuration setting or something somewhere that tells Tomcat which of the available connection pool implementations to use? – PiotrChernin Jul 03 '19 at 14:39