In a Spring MVC project I have inserted the GenericObjectPool of Apache commons. This library has done what it should for several months, until the visitor counts reached a big number. Since this time, the Jetty server breaks down with heapspace exhausted.
After analysing the heapdumps I found out, that the server after running about 2 hours included ca. 600.000 Objects of the GenericObjectPool in it’s memory which will not be destroyed. commons-dbcp as maven dependency is available in it’s actual stable version 1.4. Poorly this library includes the commons-pool in the version 1.5.4, which includes the known bug from version 1.5, where the factory methods are removed from the synconized scope to prevent deadlocks. This fix had the result, that the connections are not destroyed correctly anymore. This is resolved in the commons-pool version 1.5.5, but the stable version of commons-dbcp does not include it.
This Problem can be resolved by the following entries in the POM file:
<dependency> <groupId>commons-dbcp</groupId> <artifactId>commons-dbcp</artifactId> <version>1.4</version> <exclusions> <!-- Exclude Commons Pool 1.5.4 because using a newer version --> <exclusion> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> </exclusion> </exclusions> </dependency> <dependency> <groupId>commons-pool</groupId> <artifactId>commons-pool</artifactId> <version>1.6</version> </dependency>
Simply exclude the version 1.5.4 of commons-pool and import the newest stable version of commons-pool (actually version 1.6) single. This resolves the problem with unclosed connections.