Connection pooling and the use of a datasource is strongly recommended when moving an application into production. There are many performance benefits and it is a standard data access pattern.
The key advantage is database connections are fairly expensive operations and as such, should be reduced to a minimum in every possible use case (in edge cases, just avoided).
There are many connection pool libraries available - for extremely high-performance requirements, we would recommend https://github.com/brettwooldridge/HikariCP but the standard connection pool builtin to Tomcat is typically good enough for most applications and is the one that we will configure here.
1. Copy the JDBC jar file for the required database into <tomcat dir>/lib directory
2. Add the connection pool to the <tomcat dir>/conf/context.xml. The sample below is for MS SQL Server.
NOTE: Please change the user/password and URL to match your configuration
maxActive, initialSize, minIdle, maxIdle, etc., are all tuneable parameters and depend on your specific application load. Full details can be found here https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html
We also need to add jdbcInterceptors, these are used to ensure the connections reinitialize to the defaults, especially with respect to the autocommit flag.
3. Add the following to the deploy.properties file of your COBOL or PL/1 application, removing any other sql.* statements.
#add the dcb table entries
#use this when running from etp
NOTE: Ensure that the datasource name matches the one defined in the context.xml
Hikari Connection Pool
We can also use the Hikari connection pool, this has been benchmarked by many projects to be the fastest pool around.
The entries for this in context.xml for Hikari are as follows.
<Resource name="jdbc/testdb" auth="Container"
We also need to copy the HikariCP jar file to <tomcat home>/lib directory. Hikari also depends on SL4J logging libraries so the api and simple implementation jar need to be copied into the same directory. For JDK 8 i have attached the required files as a zip.