Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在 tomcat 服务器中设置了 JDBC 连接池。
代码 1 比代码 2 花费更多时间。我的问题是连接池是否正常工作。然后它应该并行打开其他连接并且它不应该花费太多时间(因为我有 maxActive= 100 个连接)。那么使用连接池有什么意义呢?
这很有意义。当您Connection从池中获取 a 时,它会查看它是否有可用的连接。如果池没有可用的连接,它必须通过获取连接的过程。这在您的两个示例中都是正确的。
Connection
在您的第一个循环中,每次获得连接时,池都必须分配它。池可以决定何时实际分配“initialSize” - 它可能不会立即分配。
然而,在你的第二个循环中,你得到 aConnection然后通过调用释放它close()。这会将其释放回池中。在此示例中,您可能一遍又一遍地获得相同的连接。
close()