当连接返回池时,BoneCP(或任何其他池)是否关闭连接的语句?

发布于 2024-10-05 12:44:49 字数 107 浏览 4 评论 0原文

当连接返回池时,BoneCP(或任何其他池)是否关闭连接的语句?据我了解,它不会调用实际连接的 close 方法,因此没有自动语句关闭。那么,它是否以任何其他方式关闭语句,或者我是否需要手动关闭它们?

Does BoneCP (or any other pool) close connection's statements when connection is returned to pool? As I understand, it does not call actual connection's close method, so there is no automatic statement closing. So, does it close statements in any other way or do I need to close them manually?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

歌枕肩 2024-10-12 12:44:49

JDBC 规范对于正常连接关闭时会发生什么情况非常不清楚,因此,无论您使用什么池,您都应该始终确保手动关闭语句。考虑一下,如果您选择将来切换到另一个池,而该池无法实现您期望的功能,那么您的应用程序会发生什么情况。

至于 BoneCP,答案是否定的,它不会为您关闭您的语句,尽管它可以配置为在您忘记时关闭您的连接。这是出于性能原因,因为如果您关闭连接,某些 JDBC 驱动程序将在内部关闭任何仍处于活动状态的语句。

但是,如果您启用了语句缓存,BoneCP 将关闭所有缓存的语句。

编辑:从 v0.8.0 开始,添加了对关闭未关闭语句的支持(如果需要,可以打印打开语句的位置的堆栈跟踪)。

The JDBC spec is very unclear on what should happen under normal connection close so, irrespective of the pool you use, you should always make sure to close off the statements manually. Consider what would happen to your application if you opt to switch to a different pool in the future that does not do what you expect it to do for you.

As regards BoneCP, the answer is no, it will not close off your statements for you though it can be configured to close off your connections if you forget. This is for performance reasons since some JDBC drivers will close off any still active statements internally if you close off the connection.

However, BoneCP will close off any cached statements if you have statements caching enabled.

EDIT: As of v0.8.0, support has been added to close off unclosed statements (+ print out stack trace of location where statement was opened if you want).

恍梦境° 2024-10-12 12:44:49

BoneCP (0.8.0 -RC3),有 2 种可能的结果,

仅对非缓存语句进行一些配置关闭

无论您如何配置缓存语句,都不关闭< /strong> 即使您显式调用statement.close()。

有一个StatementCache类来缓存preparedStatement &可调用语句。默认为禁用。您需要使用 >0 参数调用 BoneCPConfig.setStatementsCacheSize() 来启用它。启用缓存后,

1 BoneCP.Statement.Close() 如果被缓存,将绕过底层语句关闭。

  public void close() throws SQLException {
      this.connectionHandle.untrackStatement(this);
  this.logicallyClosed.set(true);
  if (this.logStatementsEnabled){
        this.logParams.clear();
        this.batchSQL = new StringBuilder();
      }

      if (this.cache == null || !this.inCache){ // no cache = throw it away right now
           this.internalStatement.close();
  }
}

2 BoneCP.Connection.close()
只需通过函数“clearStatementCaches()”简单地清除缓存。

好消息是,当您通过函数“closeAllOpenStatements()”关闭连接时,MYSQL JDBC 驱动程序 Connector/J 将关闭所有打开的语句

BoneCP (0.8.0 -RC3), there are 2 possible results,

close off with some configuration for non-cached statement only

non-close off no matter how you configure it for cached statement even you invoke the statement.close() explicitly.

There is a StatementCache class to cache the preparedStatement & callableStatement. The default is disabled. You need call BoneCPConfig.setStatementsCacheSize() with the >0 parameter to enable it. After enable the cache,

1 BoneCP.Statement.Close() will bypass the underlying statement close if it is cached.

  public void close() throws SQLException {
      this.connectionHandle.untrackStatement(this);
  this.logicallyClosed.set(true);
  if (this.logStatementsEnabled){
        this.logParams.clear();
        this.batchSQL = new StringBuilder();
      }

      if (this.cache == null || !this.inCache){ // no cache = throw it away right now
           this.internalStatement.close();
  }
}

2 BoneCP.Connection.close()
Will just simply clear the cache through the function "clearStatementCaches()"

The good news is MYSQL JDBC driver, Connector/J, will close all the opened statements when you close the connection through the function "closeAllOpenStatements()"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文