2 Replies Latest reply on Mar 2, 2017 9:45 AM by Mr. T

    DB Connection Max Reuse Time

    Mr. T Newbie

      As the title already suggests, is it possible to configure a maximum reuse time for pooled connections?

       

      I have the following in mind:

      Optimizing Connection Pool Behavior - Setting Connection Reuse

       

      I'm using Wildfly from version 8 Final to 10 Final.

       

      Thank you

        • 1. Re: DB Connection Max Reuse Time
          Anup Dey Apprentice

          Hi,

           

          You can use idle-timeout-minutes as per below:

           

           

          idle-timeout-minutes

          -----------------------------

           

          Idle connections are those which are *not* referenced by an application component. If an application component has requested and obtained a reference to a connection it is *not* idle until that application component executes close() (which returns it to the pool for reuse). In other words, freeing them for re-use is the responsibility of the application component.

           

          The idle-timeout-minutes is the maximum time, in minutes, before an idle connection is closed. The actual maximum time depends upon the idleRemover scan time, which is half of the smallest idle-timeout-minutes of any pool.

           

          The sequence of operations is as follows :

           

          1.  The Connection pool gets created.

          2.  The application asks for a wrapped datasource connection when it wants to perform jdbc operations.

          3.  A connection would be given to the application from the pool.

          4.  The application performs the sql and returns the connection to the pool (please note that it is the developers responsibility to close the wrapped connection in a finally block).

          5.  If the application is no longer using the connection and it is idle in the pool for more than the idle-time-out, the idleRemover destroys the idle connection. This can result in the number of physical connections being reduced to 0 or the min-pool-size

           

          The idle connection is removed by IdleRemover after :

          {<idle-timeout-minutes> + 1/2 (<idle-timeout-minutes>)}

          • 2. Re: DB Connection Max Reuse Time
            Mr. T Newbie

            I was aware of idle-timeout-minutes and i'm already doing all that you say.

            What happens is that, while some connections are indeed destroyed, others never are because they're not idle for too long. I wanted to define a max reuse time to make sure all connections are renewed, but if it's not possible then i'll decrease the idle-timeout to increase the probability of being destroyed.

             

            Thank you.