For many applications, the performance and availability of the database is paramount to keeping the revenue stream flowing. When setting up a database, administrators look to optimize the performance by how the applications use the database compared to the resources available. One element always considered is the number of connections a database can handle simultaneously. Connection pools allow applications to speed up connections by reducing the database overhead of setting up and tearing down applications, while also multiplying the number of transactions an application can handle simultaneously.
Connections in a connection pool remain open until closed, usually through garbage collection. In the case of when an application reloaded, previous connections will remain open and the application may not be able to make full use of the database, risking application availability. Forcing full garbage collection each time an application is restarted, while not elegant, would ensure your active connection pool always has connections available, although it may cause problems of its own. In a post today by Apache Tomcat 7 Release Manager, Mark Thomas, he describes a new solution to this challenge:
A new attribute has been added for JNDI resources called closeMethod which allows the system administrator to define a zero-argument method call that allows Tomcat to call on a singleton resource when that resource is no longer required. If this attribute is defined, the method is called when the application is stopped, thus speeding up the clean-up of resources that would otherwise have waited to be cleaned up as part of garbage collection.
For more information on the new closeMethod, check out Mark's full post here.