From d843138386fab9f549307d208aa074c511a71a4b Mon Sep 17 00:00:00 2001 From: hns Date: Tue, 12 Dec 2006 13:15:59 +0000 Subject: [PATCH] * Extract collection clearing in commit() and abort() into new recycle() method, and throw away collections in order to avoid retaining too much memory. --- src/helma/objectmodel/db/Transactor.java | 36 ++++++++++++++++-------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/helma/objectmodel/db/Transactor.java b/src/helma/objectmodel/db/Transactor.java index 2c18317d..b1020abc 100644 --- a/src/helma/objectmodel/db/Transactor.java +++ b/src/helma/objectmodel/db/Transactor.java @@ -113,7 +113,7 @@ public class Transactor extends Thread { /** * Keep a reference to an unmodified Node local to this transaction * - * @param node ... + * @param node the node to register */ public void visitCleanNode(Node node) { if (node != null) { @@ -128,8 +128,8 @@ public class Transactor extends Thread { /** * Keep a reference to an unmodified Node local to this transaction * - * @param key ... - * @param node ... + * @param key the key to register with + * @param node the node to register */ public void visitCleanNode(Key key, Node node) { if (node != null) { @@ -227,11 +227,11 @@ public class Transactor extends Thread { dirtyNodes.clear(); cleanNodes.clear(); parentNodes.clear(); + testedConnections.clear(); txn = nmgr.db.beginTransaction(); active = true; tstart = System.currentTimeMillis(); tname = name; - testedConnections.clear(); } /** @@ -353,10 +353,7 @@ public class Transactor extends Thread { } // clear the node collections - dirtyNodes.clear(); - cleanNodes.clear(); - parentNodes.clear(); - testedConnections.clear(); + recycle(); if (active) { active = false; @@ -398,10 +395,7 @@ public class Transactor extends Thread { } // clear the node collections - dirtyNodes.clear(); - cleanNodes.clear(); - parentNodes.clear(); - testedConnections.clear(); + recycle(); // close any JDBC connections associated with this transactor thread closeConnections(); @@ -470,6 +464,24 @@ public class Transactor extends Thread { } } + /** + * Clear collections and throw them away. They may have grown large, + * so the benefit of keeping them (less GC) needs to be weighted against + * the potential increas in memory usage. + */ + private synchronized void recycle() { + // clear the node collections to ease garbage collection + dirtyNodes.clear(); + cleanNodes.clear(); + parentNodes.clear(); + testedConnections.clear(); + // create new collections + dirtyNodes = new HashMap(); + cleanNodes = new HashMap(); + parentNodes = new HashSet(); + testedConnections = new HashSet(); + } + /** * Return the name of the current transaction. This is usually the request * path for the underlying HTTP request.