I am working with a in house DB Connection Pool which caches PreparedStatements. When the connection is returned to the pool, the cached Statements are not closed. These create OutOfMemoryExceptions in mySQL driver. So I am planning to store the PreparedStatement cache in a HashMap <String, SoftReference<PreparedStatement>>
But this does not allow me to close the Statements before they are GC’d.
Using ReferenceQueue is of no use i guess, and I have read that finalize method is not advised.
May be overriding finalize() could help?