简体   繁体   English

是否有必要在Tomcat JDBC池中显式关闭连接?

[英]Is it necessary to explicitly close connections in Tomcat JDBC pool?

Example code in " http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html " explicitly closes a connection after it is used. http://tomcat.apache.org/tomcat-7.0-doc/jdbc-pool.html ”中的示例代码在使用后显式关闭连接。

However according to my understanding, should not it be the connection pool's responsibility to manage active and idle connections? 但是根据我的理解,不应该是连接池管理活动和空闲连接的责任吗?

Why would not I want a connection to be re-used by another transaction? 为什么我不希望连接被另一个事务重用?

You must close the connection so that you can release it back to the pool. 您必须关闭连接才能将其释放回池中。 The "Connection" you get from the pool does not, per se, represent the actual, physical connection to the DB. 从池中获取的“连接”本身并不代表与DB的实际物理连接。 Rather it's a wrapper. 相反,它是一个包装。 So, closing the connection informs the pool that it is free for use by other clients of the pool. 因此,关闭连接会通知池它可供池中的其他客户端免费使用。

您需要调用Connection.close()来返回到池的连接,它实际上并不关闭底层连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Tomcat JDBC池:连接太多 - Tomcat JDBC Pool: Too many connections Tomcat JDBC池中没有足够的空闲连接 - There are not enough idle connections in Tomcat JDBC pool Tomcat JDBC连接池 - 连接处于活动状态 - Tomcat JDBC Connection Pool - Connections stuck on active Tomcat jdbc连接池,使用后不释放连接 - Tomcat jdbc connection pool, does not release connections after using 有没有办法关闭jdbc连接池中所有未使用的活动连接 - is there a way to close all unused active connections in a jdbc connection pool 关闭池中的JDBC连接 - Closing JDBC Connections in Pool org.apache.tomcat.jdbc.pool.ConnectionPool-无法使用yml文件创建池的初始连接 - org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool with yml file oatomcat.jdbc.pool.ConnectionPool:无法创建池的初始连接。 春季启动+ MySql - o.a.tomcat.jdbc.pool.ConnectionPool : Unable to create initial connections of pool. Spring Boot + MySql org.apache.tomcat.jdbc.pool.ConnectionPool - 无法创建池的初始连接 - org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool 在Tomcat中启用Context reload =“true”时,JDBC连接池用完了连接 - JDBC connection pool runs out of connections when Context reload=“true” is enabled in Tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM