You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/07/25 11:18:06 UTC

svn commit: r1506855 - /commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/PooledObjectImpl.java

Author: markt
Date: Thu Jul 25 09:18:06 2013
New Revision: 1506855

URL: http://svn.apache.org/r1506855
Log:
Trace where objects were borrowed rather than where they were created for abandoned object logging.

Modified:
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/PooledObjectImpl.java

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/PooledObjectImpl.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/PooledObjectImpl.java?rev=1506855&r1=1506854&r2=1506855&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/PooledObjectImpl.java (original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/PooledObjectImpl.java Thu Jul 25 09:18:06 2013
@@ -46,7 +46,7 @@ public class PooledObjectImpl<T> impleme
     private volatile long lastBorrowTime = createTime;
     private volatile long lastReturnTime = createTime;
     private AtomicBoolean abandonedLogConfigured = new AtomicBoolean(false);
-    private Exception createdBy = null;
+    private Exception borrowedBy = null;
     private PrintWriter logWriter = null;
 
     public PooledObjectImpl(T object) {
@@ -216,6 +216,9 @@ public class PooledObjectImpl<T> impleme
         if (state == PooledObjectState.IDLE) {
             state = PooledObjectState.ALLOCATED;
             lastBorrowTime = System.currentTimeMillis();
+            if (abandonedLogConfigured.get()) {
+                borrowedBy = new AbandonedObjectException();
+            }
             return true;
         } else if (state == PooledObjectState.EVICTION) {
             // TODO Allocate anyway and ignore eviction test
@@ -239,6 +242,9 @@ public class PooledObjectImpl<T> impleme
                 state == PooledObjectState.RETURNING) {
             state = PooledObjectState.IDLE;
             lastReturnTime = System.currentTimeMillis();
+            if (abandonedLogConfigured.get()) {
+                borrowedBy = null;
+            }
             return true;
         }
 
@@ -254,14 +260,14 @@ public class PooledObjectImpl<T> impleme
     }
 
     /**
-     * Prints the stack trace of the code that created this pooled object to
+     * Prints the stack trace of the code that borrowed this pooled object to
      * the configured log writer.  Does nothing of no PrintWriter was supplied
      * to the constructor.
      */
     @Override
     public void printStackTrace() {
-        if (createdBy != null && logWriter != null) {
-            createdBy.printStackTrace(logWriter);
+        if (borrowedBy != null && logWriter != null) {
+            borrowedBy.printStackTrace(logWriter);
         }
     }
 
@@ -298,7 +304,6 @@ public class PooledObjectImpl<T> impleme
         if (abandonedLogConfigured.compareAndSet(false, true)) {
             if (logWriter != null) {
                 this.logWriter = logWriter;
-                createdBy = new AbandonedObjectException();
             }
         }
     }