This is an automated email from the ASF dual-hosted git repository.

rmaucher pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 6c0d1b3db8c2e296e9a774139e6d8b5514cb992f
Author: opencode <[email protected]>
AuthorDate: Tue Dec 1 15:01:02 2026 +0100

    Clarify jdbc-pool idle, validation and unwrap documentation
    
    Describe minIdle as an eviction floor that borrows fill rather than a 
target the
    cleaner maintains proactively, and point at initialSize for pre-warming.
    
    Document that validationQueryTimeout relies on the JDBC driver, may need a
    driver-level socket or connect timeout when the database stops responding, 
and
    also applies to a configured initSQL.
    
    Correct the fairQueue description: the flag controls waiter fairness, while 
the
    default FairBlockingQueue hands out the most recently returned idle 
connection
    first. State that fairQueue=false hands out idle connections oldest first 
and
    can delay eviction.
    
    Warn that unwrap() returns the driver's own connection, which bypasses the 
pool
    and its interceptors and must not be closed by the application. Correct the
    example to use unwrap(Connection.class) and note that PooledConnection
    getConnection() returns the pooled logical handle.
---
 modules/jdbc-pool/doc/jdbc-pool.xml | 45 ++++++++++++++++++++++++++-----------
 1 file changed, 32 insertions(+), 13 deletions(-)

diff --git a/modules/jdbc-pool/doc/jdbc-pool.xml 
b/modules/jdbc-pool/doc/jdbc-pool.xml
index 4b202934ac..2294f569d5 100644
--- a/modules/jdbc-pool/doc/jdbc-pool.xml
+++ b/modules/jdbc-pool/doc/jdbc-pool.xml
@@ -314,6 +314,9 @@
       <p>
         (int) The minimum number of established connections that should be 
kept in the pool at all times.
         The connection pool can shrink below this number if validation queries 
fail.
+        This value is an eviction floor, not a target the pool continuously 
fills: connections are created by
+        borrows, not by the cleaner, so a pool with no borrows holds no more 
connections than its initial pre-load
+        and can stay below this number until the next borrow. Set 
<code>initialSize</code> to pre-warm the pool.
         Default value is derived from <code>initialSize</code>:<code>10</code> 
(also see <code>testWhileIdle</code>)
       </p>
     </attribute>
@@ -371,10 +374,13 @@
     </attribute>
 
     <attribute name="validationQueryTimeout" required="false">
-      <p>(int) The timeout in seconds before a connection validation queries 
fail.  This works by calling
-         <code>java.sql.Statement.setQueryTimeout(seconds)</code> on the 
statement that executes the <code>validationQuery</code>.
-         The pool itself doesn't timeout the query, it is still up to the JDBC 
driver to enforce query timeouts.
-         A value less than or equal to zero will disable this feature.
+      <p>(int) The timeout in seconds before a connection validation query 
fails. This works by calling
+         <code>java.sql.Statement.setQueryTimeout(seconds)</code> on the 
statement that executes the
+         <code>validationQuery</code>, and also on the statement that executes 
a configured <code>initSQL</code>
+         when the connection is initialized. The pool itself doesn't timeout 
the query; it is still up to the JDBC
+         driver to enforce query timeouts. Some drivers do not enforce this 
timeout once the database or network
+         stops responding, and a driver-level socket or connect timeout (for 
example <code>socketTimeout</code> or
+         <code>connectTimeout</code>) may be required. A value less than or 
equal to zero will disable this feature.
          The default value is <code>-1</code>.
       </p>
     </attribute>
@@ -410,7 +416,10 @@
     <attribute name="accessToUnderlyingConnectionAllowed" required="false">
       <p>(boolean) Property not used. Access can be achieved by calling 
<code>unwrap</code> on the pooled connection.
          see <code>javax.sql.DataSource</code> interface, or call 
<code>getConnection</code> through reflection or
-         cast the object as <code>javax.sql.PooledConnection</code></p>
+         cast the object as <code>javax.sql.PooledConnection</code>. The 
object returned by <code>unwrap</code> is
+         the driver's own connection and is not managed by the pool; closing 
it bypasses the pool and does not
+         return the connection to it. See <a 
href="#Getting_the_actual_JDBC_connection">Getting the actual JDBC
+         connection</a>.</p>
     </attribute>
 
     <attribute name="removeAbandoned" required="false">
@@ -512,11 +521,15 @@
     </attribute>
 
     <attribute name="fairQueue" required="false">
-      <p>(boolean) Set to true if you wish that calls to getConnection should 
be treated
-         fairly in a true FIFO fashion. This uses the 
<code>org.apache.tomcat.jdbc.pool.FairBlockingQueue</code>
-         implementation for the list of the idle connections. The default 
value is <code>true</code>.
+      <p>(boolean) Set to true if you wish that calls to 
<code>getConnection</code> should be treated fairly: a
+         caller that has to wait for a connection is served in the order it 
arrived. This uses the
+         <code>org.apache.tomcat.jdbc.pool.FairBlockingQueue</code> 
implementation for the list of the idle connections.
+         The default value is <code>true</code>.
          This flag is required when you want to use asynchronous connection 
retrieval.<br/>
-         Setting this flag ensures that threads receive connections in the 
order they arrive.<br/>
+         With <code>fairQueue=true</code>, idle connections are handed out 
most recently returned first, so idle
+         connections that have not been used for longer become eligible for 
eviction. With <code>fairQueue=false</code>,
+         a plain <code>java.util.concurrent.LinkedBlockingQueue</code> is used 
and idle connections are handed out
+         oldest first; frequently reused connections can then keep the whole 
pool hot and delay eviction.<br/>
          During performance tests, there is a very large difference in how 
locks
          and lock waiting is implemented. When <code>fairQueue=true</code>
          there is a decision making process based on what operating system the 
system is running.
@@ -1141,12 +1154,18 @@
   <subsection name="Getting the actual JDBC connection">
     <p>Connection pools create wrappers around the actual connection in order 
to properly pool them.
        We also create interceptors in these wrappers to be able to perform 
certain functions.
-       If there is a need to retrieve the actual connection, one can do so 
using the <code>javax.sql.PooledConnection</code>
-       interface.
+       The driver's own connection is reached through 
<code>isWrapperFor()</code> and <code>unwrap()</code> on the
+       pooled handle:
     </p>
 <source><![CDATA[  Connection con = datasource.getConnection();
-  Connection actual = 
((javax.sql.PooledConnection)con).getConnection();]]></source>
-
+  Connection actual = con.unwrap(Connection.class);]]></source>
+    <p>The object returned by <code>unwrap()</code> is the driver's own 
connection, not a pool proxy: the pool
+       does not see calls made through it, its interceptors do not apply, and 
closing it closes the physical session
+       without returning the connection to the pool. Use it only while the 
pooled handle is borrowed, and never
+       close, abort or change session state through it. The pooled handle is 
the object that must be closed to
+       return the connection to the pool; its 
<code>javax.sql.PooledConnection.getConnection()</code> accessor
+       returns the pooled logical handle, not the driver session.
+    </p>
   </subsection>
 
 </section>


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to