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 2009/11/19 12:35:16 UTC
svn commit: r882113 - in /commons/proper/dbcp/trunk:
src/java/org/apache/commons/dbcp/AbandonedTrace.java xdocs/changes.xml
Author: markt
Date: Thu Nov 19 11:35:14 2009
New Revision: 882113
URL: http://svn.apache.org/viewvc?rev=882113&view=rev
Log:
Fix DBCP-305. Patch (slightly modified) provided by Christopher Schultz.
Modified:
commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/AbandonedTrace.java
commons/proper/dbcp/trunk/xdocs/changes.xml
Modified: commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/AbandonedTrace.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/AbandonedTrace.java?rev=882113&r1=882112&r2=882113&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/AbandonedTrace.java (original)
+++ commons/proper/dbcp/trunk/src/java/org/apache/commons/dbcp/AbandonedTrace.java Thu Nov 19 11:35:14 2009
@@ -35,17 +35,10 @@
*/
public class AbandonedTrace {
- /** Date format */
- private static final SimpleDateFormat format = new SimpleDateFormat
- ("'DBCP object created' yyyy-MM-dd HH:mm:ss " +
- "'by the following code was never closed:'");
-
/** DBCP AbandonedConfig */
private AbandonedConfig config = null;
/** A stack trace of the code that created me (if in debug mode) */
private volatile Exception createdBy;
- /** Time created */
- private volatile long createdTime;
/** A list of objects created by children of this object */
private final List trace = new ArrayList();
/** Last time this connection was used */
@@ -93,8 +86,7 @@
return;
}
if (config.getLogAbandoned()) {
- createdBy = new Exception();
- createdTime = System.currentTimeMillis();
+ createdBy = new AbandonedObjectException();
}
}
@@ -143,8 +135,7 @@
return;
}
if (config.getLogAbandoned()) {
- createdBy = new Exception();
- createdTime = System.currentTimeMillis();
+ createdBy = new AbandonedObjectException();
}
}
@@ -188,7 +179,6 @@
*/
public void printStackTrace() {
if (createdBy != null && config != null) {
- config.getLogWriter().println(format.format(new Date(createdTime)));
createdBy.printStackTrace(config.getLogWriter());
}
synchronized(this.trace) {
@@ -203,7 +193,7 @@
/**
* Remove a child object this object is tracing.
*
- * @param trace AbandonedTrace object to remvoe
+ * @param trace AbandonedTrace object to remove
*/
protected void removeTrace(AbandonedTrace trace) {
synchronized(this.trace) {
@@ -211,4 +201,27 @@
}
}
+ static class AbandonedObjectException extends Exception {
+
+ /** Date format */
+ private static final SimpleDateFormat format = new SimpleDateFormat
+ ("'DBCP object created' yyyy-MM-dd HH:mm:ss " +
+ "'by the following code was never closed:'");
+
+ private long _createdTime;
+
+ public AbandonedObjectException() {
+ _createdTime = System.currentTimeMillis();
+ }
+
+ // Override getMessage to avoid creating objects and formatting
+ // dates unless the log message will actually be used.
+ public String getMessage() {
+ String msg;
+ synchronized(format) {
+ msg = format.format(new Date(_createdTime));
+ }
+ return msg;
+ }
+ }
}
Modified: commons/proper/dbcp/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/xdocs/changes.xml?rev=882113&r1=882112&r2=882113&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/xdocs/changes.xml (original)
+++ commons/proper/dbcp/trunk/xdocs/changes.xml Thu Nov 19 11:35:14 2009
@@ -42,6 +42,11 @@
new features as well as bug fixes and instrumentation. Some bug fixes
will change semantics (e.g. connection close will become idempotent).
The minimum JDK level will be increased to 1.4">
+ <action dev="markt" type="update" issue="DBCP-305" due-to="Christopher Schultz">
+ Use an API specific exception for logging abandoned objects to make
+ scanning the logs for these exceptions simpler and to provide a better
+ message that includes the creation time of the abandoned object.
+ </action>
<action dev="markt" type="fix" issue="DBCP-303" due-to="Dave Oxley">
Ensure Statement.getGeneratedKeys() works correctly with the CPDS
adapter.