Why does my Tomcat only open 8 JDBC connections

六月ゝ 毕业季﹏ 提交于 2019-11-28 12:43:26
Norbert van Nobelen

Quote from "Tomcat Expert: Configuring jdbc-pool for high-concurrency":

When Tomcat reads the type="javax.sql.DataSource" it will automatically configure its repackaged DBCP, unless you specify a different factory. The factory object is what creates and configures the connection pool itself.

It turns out that DBCP package just ignores a series of settings. Adding the following line to the context.xml resource configuration, gets better response in the database:

<Resource 
 ....
factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
 ....
/>

Show processlist in mysql then immediately shows the desired behaviour.

By default (ie if not setting the factory setting of your ressource), tomcat7 uses commons dbcp1.

Tomcat also provides an alternate pool implementation (the tomcat jdbc connection pool) that you can use by setting factory=org.apache.tomcat.jdbc.pool.DataSourceFactory on your ressource

Tomcat8 uses commons dbcp2 by default, which has different names for some very important configuration parameters ( see https://tomcat.apache.org/migration-8.html#Database_Connection_Pooling ) as dbcp1 (and the tomcat jdbc connection pool, because it mostly has the same configuration options as commons dbcp1).

So basically, before tomcat8, you didn't have to pay attention to which connection pool you were using because of the configuration compatibilty. With tomcat8, you have to pay attention.

Tomcat connection pool documentation: https://tomcat.apache.org/tomcat-8.0-doc/jdbc-pool.html

Default commons dbcp2 documentation: https://tomcat.apache.org/tomcat-8.0-doc/jndi-resources-howto.html#JDBC_Data_Sources

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!