Author: kfujino Date: Mon Nov 21 02:19:24 2016 New Revision: 1770601 URL: http://svn.apache.org/viewvc?rev=1770601&view=rev Log: Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=58816 Implement the statistics of jdbc-pool. The stats infos are borrowedCount, returnedCount, createdCount and releasedCount.
Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1770601&r1=1770600&r2=1770601&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Mon Nov 21 02:19:24 2016 @@ -128,6 +128,14 @@ public class ConnectionPool { private AtomicLong poolVersion = new AtomicLong(Long.MIN_VALUE); + /** + * The counters for statistics of the pool. + */ + private final AtomicLong borrowedCount = new AtomicLong(0); + private final AtomicLong returnedCount = new AtomicLong(0); + private final AtomicLong createdCount = new AtomicLong(0); + private final AtomicLong releasedCount = new AtomicLong(0); + //=============================================================================== // PUBLIC METHODS //=============================================================================== @@ -598,6 +606,7 @@ public class ConnectionPool { size.addAndGet(-1); con.setHandler(null); } + releasedCount.incrementAndGet(); } finally { con.unlock(); } @@ -633,6 +642,7 @@ public class ConnectionPool { if (con!=null) { //configure the connection and return it PooledConnection result = borrowConnection(now, con, username, password); + borrowedCount.incrementAndGet(); if (result!=null) return result; } @@ -725,6 +735,7 @@ public class ConnectionPool { if (!busy.offer(con)) { log.debug("Connection doesn't fit into busy array, connection will not be traceable."); } + createdCount.incrementAndGet(); return con; } else { //validation failed, make sure we disconnect @@ -896,6 +907,7 @@ public class ConnectionPool { if (con != null) { try { + returnedCount.incrementAndGet(); con.lock(); if (con.isSuspect()) { if (poolProperties.isLogAbandoned() && log.isInfoEnabled()) { @@ -1177,6 +1189,38 @@ public class ConnectionPool { } /** + * The total number of connections borrowed from this pool. + * @return the borrowed connection count + */ + public long getBorrowedCount() { + return borrowedCount.get(); + } + + /** + * The total number of connections returned to this pool. + * @return the returned connection count + */ + public long getReturnedCount() { + return returnedCount.get(); + } + + /** + * The total number of connections created by this pool. + * @return the created connection count + */ + public long getCreatedCount() { + return createdCount.get(); + } + + /** + * The total number of connections released from this pool. + * @return the released connection count + */ + public long getReleasedCount() { + return releasedCount.get(); + } + + /** * Tread safe wrapper around a future for the regular queue * This one retrieves the pooled connection object * and performs the initialization according to Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java?rev=1770601&r1=1770600&r2=1770601&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/DataSourceProxy.java Mon Nov 21 02:19:24 2016 @@ -752,6 +752,55 @@ public class DataSourceProxy implements throw new RuntimeException(x); } } + + /** + * The total number of connections borrowed from this pool. + * @return the borrowed connection count + */ + public long getBorrowedCount() { + try { + return createPool().getBorrowedCount(); + } catch (SQLException x) { + throw new RuntimeException(x); + } + } + + /** + * The total number of connections returned to this pool. + * @return the returned connection count + */ + public long getReturnedCount() { + try { + return createPool().getReturnedCount(); + } catch (SQLException x) { + throw new RuntimeException(x); + } + } + + /** + * The total number of connections created by this pool. + * @return the created connection count + */ + public long getCreatedCount() { + try { + return createPool().getCreatedCount(); + } catch (SQLException x) { + throw new RuntimeException(x); + } + } + + /** + * The total number of connections released from this pool. + * @return the released connection count + */ + public long getReleasedCount() { + try { + return createPool().getReleasedCount(); + } catch (SQLException x) { + throw new RuntimeException(x); + } + } + //========================================================= // PROPERTIES / CONFIGURATION //========================================================= Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java?rev=1770601&r1=1770600&r2=1770601&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java Mon Nov 21 02:19:24 2016 @@ -166,6 +166,26 @@ public class ConnectionPool extends Noti return pool.getWaitCount(); } + @Override + public long getBorrowedCount() { + return pool.getBorrowedCount(); + } + + @Override + public long getReturnedCount() { + return pool.getReturnedCount(); + } + + @Override + public long getCreatedCount() { + return pool.getCreatedCount(); + } + + @Override + public long getReleasedCount() { + return pool.getReleasedCount(); + } + //================================================================= // POOL OPERATIONS //================================================================= Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java?rev=1770601&r1=1770600&r2=1770601&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPoolMBean.java Mon Nov 21 02:19:24 2016 @@ -35,6 +35,14 @@ public interface ConnectionPoolMBean ext public int getWaitCount(); + public long getBorrowedCount(); + + public long getReturnedCount(); + + public long getCreatedCount(); + + public long getReleasedCount(); + //================================================================= // POOL OPERATIONS //================================================================= Modified: tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml?rev=1770601&r1=1770600&r2=1770601&view=diff ============================================================================== --- tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml (original) +++ tomcat/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/mbeans-descriptors.xml Mon Nov 21 02:19:24 2016 @@ -330,6 +330,26 @@ is="true" writeable="false"/> + <attribute name="borrowedCount" + description="The total number of connections borrowed from this pool" + type="java.lang.Long" + writeable="false"/> + + <attribute name="createdCount" + description="The total number of connections created by this pool" + type="java.lang.Long" + writeable="false"/> + + <attribute name="returnedCount" + description="The total number of connections returned to this pool" + type="java.lang.Long" + writeable="false"/> + + <attribute name="releasedCount" + description="The total number of connections released from this pool" + type="java.lang.Long" + writeable="false"/> + <operation name="checkIdle" description="forces a check of idle connections" impact="ACTION" Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1770601&r1=1770600&r2=1770601&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Nov 21 02:19:24 2016 @@ -109,6 +109,11 @@ </subsection> <subsection name="jdbc-pool"> <changelog> + <add> + <bug>58816</bug>: Implement the statistics of jdbc-pool. The stats infos + are <code>borrowedCount</code>, <code>returnedCount</code>, + <code>createdCount</code> and <code>releasedCount</code>. (kfujino) + </add> <fix> <bug>60194</bug>: If <code>validationQuery</code> is not specified, connection validation is done by calling the <code>isValid()</code> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org