Search code examples
tomcattomcat9

Override maxWait in tomcat 9


I have a tomcat server and under tomcatFolder/conf/server.xml I got this tag Resource

<Resource name="jdbc/TestDB"
      auth="Container"
      type="javax.sql.DataSource"
      factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
      testWhileIdle="true"
      testOnBorrow="true"
      testOnReturn="false"
      validationQuery="SELECT 1"
      validationInterval="30000"
      timeBetweenEvictionRunsMillis="30000"
      maxActive="100"
      minIdle="10"
      maxWait="10000"
      initialSize="10"
      removeAbandonedTimeout="60"
      removeAbandoned="true"
      logAbandoned="true"
      minEvictableIdleTimeMillis="30000"
      jmxEnabled="true"
      jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;
        org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"
      username="root"
      password="password"
      driverClassName="com.mysql.jdbc.Driver"
      url="jdbc:mysql://localhost:3306/mysql"/>

How can I override the maxWait value in setenv.sh or in catalina.sh run command ??


Solution

  • I'm not sure how to /override/, but you can define a value in setenv.sh and use it in a configuration file. For example:

        # setenv.sh
        JAVA_OPTS="$JAVA_OPTS -Djdbc.maxWait=5000"
    
        <!-- server.xml or context.xml -->
        <Resource name=...
            ...
            maxWait="${jdbc.maxWait}"
            ...
    

    UPDATE:

    Tomcat releases 9.0.34 and 8.5.54 add support for default values when using ${...} property replacement in configuration files. For 9.0.34 and 8.5.54 the separator is a colon character. e.g.

    maxWait="${jdbc.maxWait:10000}"
    

    For 9.0.35 and 8.5.55 the separator was changed to be :-. e.g.

    maxWait="${jdbc.maxWait:-10000}"
    

    (Thanks to the comments by Piotr P. Karwasz)