Uploaded image for project: 'TomEE'
  1. TomEE
  2. TOMEE-2125

Datasource config: MaxWait, timeBetweenEvictionRunsMillis and MinEvictableIdleTimeMillis are ignored

    XMLWordPrintableJSON

    Details

      Description

      MaxWait Property is ignored because it will always be removed.
      As example, this is my configuration in tomee.xml

      <Resource id="database" type="javax.sql.DataSource">
              JdbcDriver = com.mysql.jdbc.Driver
              JdbcUrl = jdbc:mysql://localhost:3306/dbname?useSSL=false
              UserName = username
              Password = somepw
              MaxActive = 20
              MaxIdle = 20
              MinIdle = 2
              InitialSize = 2
              MaxWait = 5000
              TestOnBorrow = true
              ValidationQuery = select 1
              timeBetweenEvictionRuns = 7200000
              MinEvictableIdleTimeMillis = 7200000
              TestWhileIdle = true
          </Resource>
      

      The error is in the file openejb-core-7.0.3.jar!\org\apache\openejb\resource\jdbc\DataSourceFactory where it looks for values, instead of looking for key (line 356):

      private static void convert(Properties properties, Duration duration, String key, String oldKey) {
              properties.remove(key);
              if(!properties.contains(oldKey)) {
                  properties.remove(oldKey);
                  if(duration != null) {
                      if(duration.getUnit() == null) {
                          duration.setUnit(TimeUnit.MILLISECONDS);
                      }
      
                      long milliseconds = TimeUnit.MILLISECONDS.convert(duration.getTime(), duration.getUnit());
                      properties.put(oldKey, String.valueOf(milliseconds));
                  }
              }
          }
      

      properties.contains(oldKey) should be replaced by properties.containsKey(oldKey)

      So all properties which uses this convert method are ignored:

      convert(properties, maxWaitTime, "maxWaitTime", "maxWait");
      convert(properties, timeBetweenEvictionRuns, "timeBetweenEvictionRuns", "timeBetweenEvictionRunsMillis");
      convert(properties, minEvictableIdleTime, "minEvictableIdleTime", "minEvictableIdleTimeMillis");
      

      WORKAROUD
      To avoid that, it is possible to have fake properties in tomee.xml with the ignored property as value (see the ignoreMe properties at the end):

          <Resource id="smclient" type="javax.sql.DataSource">
              JdbcDriver = com.mysql.jdbc.Driver
              JdbcUrl = jdbc:mysql://localhost:3306/dbname?useSSL=false
              UserName = username
              Password = somepw
              MaxActive = 20
              MaxIdle = 20
              MinIdle = 2
              InitialSize = 2
              MaxWait = 5000
              TestOnBorrow = true
              ValidationQuery = select 1
              timeBetweenEvictionRunsMillis = 7200000
              MinEvictableIdleTimeMillis = 7200000
              TestWhileIdle = true
              ignoreMe = maxWait
              ignoreMe2 = timeBetweenEvictionRunsMillis
              ignoreMe3 = minEvictableIdleTimeMillis
          </Resource>
      

      Then the values are correctly set to the datasources (verified with visualvm in the datasource MBean)

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                rzo1 Richard Zowalla
                Reporter:
                sberthouzoz Sylvain Berthouzoz
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 50m
                  50m