jettytomcat-jdbc

Jetty with tomcat-jdbc connection pool


Jetty manual provides connection pool examples with BoneCP, c3p0, DBCP but not tomcat-jdbc. Is it possible to configure Jetty with tomcat-jdbc connection pool?


Solution

  • I have been using this configuration with jetty 9.3 and tomcat-jdbc 7.0.72

      <!-- =========================================================== -->
      <!-- DataSource                                                  -->
      <!-- =========================================================== -->
    
      <New id="rfid" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>jdbc/rfid</Arg>
        <Arg>
          <New class="org.apache.tomcat.jdbc.pool.DataSource">
            <Set name="driverClassName">oracle.jdbc.OracleDriver</Set>
            <Set name="url">jdbc:oracle:thin:@integra:1521:integra</Set>
            <Set name="username">user</Set>
            <Set name="password">password</Set>
            <Set name="defaultAutoCommit">false</Set>
            <Set name="jmxEnabled">true</Set>
            <Set name="testWhileIdle">false</Set>
            <Set name="testOnBorrow">true</Set>
            <Set name="testOnReturn">false</Set>
            <Set name="validationQuery">SELECT 1 FROM dual</Set>
            <Set name="validationInterval">30000</Set>
            <Set name="minEvictableIdleTimeMillis">30000</Set>
            <Set name="timeBetweenEvictionRunsMillis">30000</Set>
            <Set name="initialSize">8</Set>
            <Set name="minIdle">8</Set>
            <Set name="maxIdle">8</Set>
            <Set name="maxActive">10</Set>
            <Set name="maxWait">30000</Set>
            <Set name="removeAbandonedTimeout">120</Set>
            <Set name="logAbandoned">true</Set>
            <Set name="removeAbandoned">true</Set>
            <Set name="jdbcInterceptors">
              org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=2000);
              org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx;
            </Set>
          </New>
        </Arg>
      </New>
    
      <New id="myphoto" class="org.eclipse.jetty.plus.jndi.Resource">
        <Arg>jdbc/myphoto</Arg>
        <Arg>
          <New class="org.apache.tomcat.jdbc.pool.DataSource">
            <Set name="driverClassName">com.mysql.jdbc.Driver</Set>
            <Set name="url">jdbc:mysql://localhost:3306/myphotoipb?zeroDateTimeBehavior=convertToNull&amp;useSSL=false</Set>
            <Set name="username">myphoto</Set>
            <Set name="password">password</Set>
            <Set name="defaultAutoCommit">false</Set>
            <Set name="jmxEnabled">true</Set>
            <Set name="testWhileIdle">false</Set>
            <Set name="testOnBorrow">true</Set>
            <Set name="testOnReturn">false</Set>
            <Set name="validationQuery">SELECT 1 FROM dual</Set>
            <Set name="validationInterval">30000</Set>
            <Set name="minEvictableIdleTimeMillis">30000</Set>
            <Set name="timeBetweenEvictionRunsMillis">30000</Set>
            <Set name="initialSize">2</Set>
            <Set name="minIdle">4</Set>
            <Set name="maxIdle">8</Set>
            <Set name="maxActive">10</Set>
            <Set name="maxWait">30000</Set>
            <Set name="removeAbandonedTimeout">120</Set>
            <Set name="logAbandoned">true</Set>
            <Set name="removeAbandoned">true</Set>
            <Set name="jdbcInterceptors">
              org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport(threshold=2000);
              org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx;
            </Set>
          </New>
        </Arg>
      </New>