pgjdbc/pgjdbc — pull request #188 by metlos (2014-09-18 11:13:07+00:00)
Title: Avoid a classloader leak through a dangling statement cancel timer thread.

When the driver class was loaded, it started a Timer thread that was used
to cancel statements on timeout. This timer thread was never stopped.

When the class is loaded in containerized environment (web container,
ee container, ...) this might lead to eventual permgen depletion when the
deployment with the driver is merely reloaded (which may involve reloading
the classes of the deployment) repeatedly.

The timer thread holds on to the protection domain of the code that created
it and that protection domain holds on to the classloader that is used to
load the classes. Through this chain of references, the dangling threads
cause the classloader of the "previous" deployments to never be GC'ed and
their classes unloaded.

The fix is to have the cancel timer thread per-connection and tear it down
when closing the connection.

Note that exactly the same issue existed in MySQL JDBC driver where it was
fixed in 2009:
http://bugs.mysql.com/bug.php?id=36565