I understand that finalizers are a bad thing to use, even for connection closing (Is closing the connection in finalize best practice?), since they are not guaranteed to be called. But what if your connections are pooled via a connection pool? In my case, I'm using Apache Commons pool (http://commons.apache.org/proper/commons-pool/) to pool SFTP connections. I can't use the try-with-resources technique because each connection should not be closed at the end of every try (so that it can be potentially re-used by the pool for the next action).
I do provide a closePool() method that calls pool.close() so that whatever programmer uses my code can call it, but what if she/he forgets to do so? Is calling this method from a finalizer the best solution to try and close the connection pool in case it's not done manually, or is there a better way? Would a shutdown hook work better for this?