4 Replies Latest reply on Aug 16, 2018 5:27 AM by tomjenkinson

    How to stop the evictor-thread ?

    aquamarine.m.b.s

      We have developed web application server for enterprise with your org.jboss.narayana.tomcat.jta.TransactionalDataSourceFactory.

      When we set on timeBetweenEvictionRunsMillis, tomcat can't be stopped.

       

      The reason is the following thread dump:

      "commons-pool-evictor-thread" #40 prio=5 os_prio=0 tid=0x0000000021389800 nid=0x7408 waiting on condition [0x000000002776e000]

         java.lang.Thread.State: TIMED_WAITING (parking)

       

      We already checked that tomcat can be stopped when timeBetweenEvictionRunsMillis is not set.

       

      Please tell me how to stop the evictor-thread ?

       

      Tomcat 9.0.8

       

      narayana ver.

              <dependency>

                  <groupId>org.jboss.narayana.tomcat</groupId>

                  <artifactId>tomcat-jta</artifactId>

                  <version>5.8.2.Final</version>

              </dependency>

       

      context.xml

          <Transaction factory="org.jboss.narayana.tomcat.jta.UserTransactionFactory" />
          
          <Resource
              factory="org.jboss.narayana.tomcat.jta.TransactionManagerFactory"
              name="TransactionManager"
              type="javax.transaction.TransactionManager"/>
                  
          <Resource
              factory="org.jboss.narayana.tomcat.jta.TransactionSynchronizationRegistryFactory"
              name="TransactionSynchronizationRegistry"
              type="javax.transaction.TransactionSynchronizationRegistry" />
                  
          <Resource
              name="postgresDS"
              uniqueName="myDataSource"
              auth="Container"
              type="org.postgresql.xa.PGXADataSource"
              factory="org.postgresql.xa.PGXADataSourceFactory"
              databaseName="DATABASE_NAME"
              jmxEnabled="true"
              user="USER"
              password="PASSWORD"
              portNumber="PORT"
              serverName="SERVER_NAME"/>
      
          <Resource
              name="transactionalDataSource"
              uniqueName="transactionalDataSource"
              auth="Container"
              xaDataSource="postgresDS"
              type="javax.sql.XADataSource"
              factory="org.jboss.narayana.tomcat.jta.TransactionalDataSourceFactory"
              transactionManager="TransactionManager"
              driverClassName="com.arjuna.ats.jdbc.TransactionalDriver"
              username="USER"
              initialSize="INITIAL_SIZE"
              minIdle="MIN_IDLE"
              maxIdle="MAX_IDLE"
              maxTotal="MAX_TOTAL"
              poolPreparedStatements="true"
              maxOpenPreparedStatements="MAX_OPEN_PREPARED_STATEMENTS"
              jmxEnabled="true"
              timeBetweenEvictionRunsMillis="TIME_BETWEEN_EVICTION_RUNS_MILLIS"
              maxWaitMillis="MAX_WAIT_MILLIS"
              autoCommit="false"
              jmxName="Catalina:type=Resource,resourcetype=DataSource,context=/dl,name=dataSource"
              validationQuery="SELECT 1"
              validationInterval="10000"/>
      
        • 1. Re: How to stop the evictor-thread ?
          tomjenkinson

          This is somewhat of a question for the commons pool and commons dbcp teams.

           

          For now I did find:

          commons-pool/EvictionTimer.java at 7411f1083ed3fb4fc8277a28205e9530d6bf1a46 · apache/commons-pool · GitHub

           

          Which mentions it should not cause a shutdown hang. Perhaps there is a connection open still that is somehow leaving it like this? Are you able to provide more of a stack dump?

           

          I guess you know this but -1 disables that setting: DBCP – BasicDataSource Configuration

           

          I also found where DBCP is passing the config over to the pool:

          commons-dbcp/DriverAdapterCPDS.java at d815c27f7652dce234403fd95b55278a0423b5b6 · apache/commons-dbcp · GitHub

          • 2. Re: How to stop the evictor-thread ?
            zhfeng

            I found this case java - DBCP2 - When are Idle connections removed from the Pool - Stack Overflow  could be useful. It looks like if the minIdle is larger than 0, the evictor thread could be alive at least TIME_BETWEEN_EVICTION_RUNS_MILLIS seconds.

            Anyway, your case are more related to the DBCP configuration as Tom suggested.

            • 3. Re: How to stop the evictor-thread ?
              aquamarine.m.b.s

              Thank you for your reply.

              We solved the problem.

               

               

               

               

              TestContextListener.java

               

               

              package sample.listener;

               

               

              import java.sql.SQLException;

              import java.time.LocalDateTime;

               

               

              import javax.naming.Context;

              import javax.naming.InitialContext;

              import javax.naming.NamingException;

              import javax.servlet.ServletContext;

              import javax.servlet.ServletContextEvent;

              import javax.servlet.ServletContextListener;

              import org.apache.tomcat.dbcp.dbcp2.managed.BasicManagedDataSource;

               

               

              public class TestContextListener implements ServletContextListener {

                  @Override

                  public void contextInitialized(ServletContextEvent sce) {

                      // nop

                  }

               

               

                  @Override

                  public void contextDestroyed(ServletContextEvent sce) {

                      System.out.print(LocalDateTime.now());

                      System.out.print(" Context destroyed [path=");

                      System.out.print(path(sce.getServletContext()));

                      System.out.println("]");

               

               

                      try {

                          Context initCtx = new InitialContext();

                          Context envCtx = (Context) initCtx.lookup("java:comp/env");

                          BasicManagedDataSource bds = (BasicManagedDataSource) envCtx.lookup("transactionalDataSource");

                          bds.close();

                      } catch (NamingException e) {

                          e.printStackTrace();

                      } catch (SQLException e) {

                          e.printStackTrace();

                      } catch (Exception e) {

                          e.printStackTrace();

                      }

                  }

               

               

                  private String path(ServletContext sc) {

                      String path = sc.getContextPath();

                      if (path == null | "".equals(path))

                          return "/";

                      else

                          return path;

                  }

              }

               

               

               

               

              web.xml

                  <listener>

                      <listener-class>sample.listener.TestContextListener</listener-class>

                  </listener>

              • 4. Re: How to stop the evictor-thread ?
                tomjenkinson

                Thanks for getting back to us - it seems the datasource close is likely the part you were missing then?