Tomcat connection pooling with prepared statement cache

十年热恋 提交于 2020-01-01 07:02:08

问题


Having upgraded from DBCP connection pooling to Tomcat's own implementation (based on the excellent comparison here); I'm a little confused as to why they've dropped these 2 properties, while keeping everything else:

poolPreparedStatements="true"
maxOpenPreparedStatements="10000"

Does this mean that prepared statement pooling is not supported in this implementation? And does each connection maintain its own pool of prepared statements by default?

I've spent a considerable time researching this and have found no clear answer!

Thanks for your time.


回答1:


Tomcat's (fairly) new jdbc-pool does have a statement cache, too. You can enable and configure it using a JDBC interceptor, which is set as a JDBC property during pool creation.
Please have a look at the documentation for more information and which configuration possibilities exist.

It's basically done this way:

      PoolProperties p = new PoolProperties();
      p.setUrl("jdbc:your-jdbc-url");
      p.setDriverClassName("your.jdbc.driver.class");
      p.setUsername("user");
      p.setPassword("password");
      p.setJdbcInterceptors(
        "org.apache.tomcat.jdbc.pool.interceptor.StatementCache");
      DataSource datasource = new DataSource();
      datasource.setPoolProperties(p);


来源:https://stackoverflow.com/questions/15527791/tomcat-connection-pooling-with-prepared-statement-cache

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