Why does my Tomcat only open 8 JDBC connections

后端 未结 2 896
再見小時候
再見小時候 2020-12-11 09:35

When setting up the database connections in Tomcat 8, for some reason Tomcat is not following what I configured in the context.xml, with as result that I run out of connecti

相关标签:
2条回答
  • 2020-12-11 10:17

    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

    0 讨论(0)
  • 2020-12-11 10:33

    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.

    0 讨论(0)
提交回复
热议问题