You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kf...@apache.org on 2016/11/21 05:16:14 UTC
svn commit: r1770616 -
/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
Author: kfujino
Date: Mon Nov 21 05:16:14 2016
New Revision: 1770616
URL: http://svn.apache.org/viewvc?rev=1770616&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/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
Modified: tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java?rev=1770616&r1=1770615&r2=1770616&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java (original)
+++ tomcat/tc7.0.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/ConnectionPool.java Mon Nov 21 05:16:14 2016
@@ -130,6 +130,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
//===============================================================================
@@ -597,6 +605,7 @@ public class ConnectionPool {
size.addAndGet(-1);
con.setHandler(null);
}
+ releasedCount.incrementAndGet();
} finally {
con.unlock();
}
@@ -630,6 +639,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;
}
@@ -720,6 +730,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
@@ -890,6 +901,7 @@ public class ConnectionPool {
if (con != null) {
try {
+ returnedCount.incrementAndGet();
con.lock();
if (con.isSuspect()) {
if (poolProperties.isLogAbandoned() && log.isInfoEnabled()) {
@@ -1169,6 +1181,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
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org