简体   繁体   English

在 Tomcat 中测试连接池

[英]Testing Connection pool in Tomcat

I have a JDBC connection pool setup in tomcat server.我在 tomcat 服务器中设置了 JDBC 连接池。

在此处输入图像描述 Code 1 takes more time than Code 2. My question is that if connection pool is working.代码 1 比代码 2 花费更多时间。我的问题是连接池是否正常工作。 Then it should parallelly open other connections and it should not be taking much time ( as I have maxActive= 100 connections ).然后它应该并行打开其他连接并且它不应该花费太多时间(因为我有 maxActive= 100 个连接)。 Then what is the point in using connection pool?那么使用连接池有什么意义呢?

This makes perfect sense.这很有意义。 When you get a Connection from the pool it looks to see if it has a Connection available.当您从池中获取Connection时,它会查看是否有可用的连接。 If the pool doesn't have an available connection it has to go through the process of obtaining the connection.如果池没有可用的连接,它必须通过获取连接的过程到 go。 This is true in both of your examples.这在您的两个示例中都是正确的。

In your first loop, every time you get a connection the pool has to allocate it.在您的第一个循环中,每次获得连接时,池都必须分配它。 Pools get to decide when the "initialSize" is actually allocated - it may not be instantly.池可以决定何时实际分配“initialSize” - 它可能不会立即分配。

In your second loop, however, you get a Connection and then release it by calling close() .然而,在你的第二个循环中,你得到一个Connection ,然后通过调用close()释放它。 This releases it back to the pool.这会将其释放回池中。 In this example it's likely you're getting the same connection over and over again.在此示例中,您可能一遍又一遍地获得相同的连接。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM