我正在使用缓存 PreparedStatements 的内部数据库连接池。当连接返回到池中时,缓存的 Statements 不会关闭。这些在 mySQL 驱动程序中创建 OutOfMemoryExceptions。所以我打算将 PreparedStatement 缓存存储在 HashMap <String, SoftReference<PreparedStatement>>
但这不允许我在语句被 GC 之前关闭它们。
我猜使用 ReferenceQueue 没有用,而且我已经读过不建议使用 finalize 方法。