You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ode.apache.org by bo...@apache.org on 2007/09/11 00:36:19 UTC

svn commit: r574393 - /ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java

Author: boisvert
Date: Mon Sep 10 15:36:14 2007
New Revision: 574393

URL: http://svn.apache.org/viewvc?rev=574393&view=rev
Log:
Fix bug with in-memory instance collector (start time was not being recorded)

Modified:
    ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java

Modified: ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java
URL: http://svn.apache.org/viewvc/ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java?rev=574393&r1=574392&r2=574393&view=diff
==============================================================================
--- ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java (original)
+++ ode/branches/APACHE_ODE_1.1/bpel-runtime/src/main/java/org/apache/ode/bpel/memdao/ProcessDaoImpl.java Mon Sep 10 15:36:14 2007
@@ -108,25 +108,12 @@
         _conn.defer(new Runnable() {
             public void run() {
                 _instances.put(newInstance.getInstanceId(), newInstance);
+                _instancesAge.put(newInstance.getInstanceId(), System.currentTimeMillis());
             }
         });
-        long now = System.currentTimeMillis();
-
-        // Checking for old instances that could still be around because of a failure
-        // or completion problem
-        if (now > _lastRemoval + (BpelDAOConnectionImpl.TIME_TO_LIVE/10)) {
-            _lastRemoval = now;
-            Object[] oldInstances = _instancesAge.keySet().toArray();
-            for (int i=oldInstances.length-1; i>0; i--) {
-                Long old = (Long) oldInstances[i];
-                Long age = _instancesAge.get(old);
-                if (age != null && now-age > BpelDAOConnectionImpl.TIME_TO_LIVE) {
-                    _instances.remove(old);
-                    _instancesAge.remove(old);
-                }
-            }
-        }
 
+        discardOldInstances();
+        
         // Removing right away on rollback
         final Long iid = newInstance.getInstanceId();
         _conn.onRollback(new Runnable() {
@@ -157,7 +144,7 @@
     public void instanceCompleted(ProcessInstanceDAO instance) {
         // Cleaning up
         if (__log.isDebugEnabled())
-        __log.debug("Removing completed process instance " + instance.getInstanceId() + " from in-memory store.");
+          __log.debug("Removing completed process instance " + instance.getInstanceId() + " from in-memory store.");
         _instancesAge.remove(instance.getInstanceId());
         ProcessInstanceDAO removed = _instances.remove(instance.getInstanceId());
         if (removed == null) {
@@ -226,5 +213,25 @@
     
     public void setGuid(String guid) {
         _guid = guid;
+    }
+
+    /**
+     * Discard in-memory instances that exceeded their time-to-live to prevent memory leaks
+     */
+    void discardOldInstances() {
+        long now = System.currentTimeMillis();
+        if (now > _lastRemoval + (BpelDAOConnectionImpl.TIME_TO_LIVE/10)) {
+            _lastRemoval = now;
+            Object[] oldInstances = _instancesAge.keySet().toArray();
+            for (int i=oldInstances.length-1; i>=0; i--) {
+                Long id = (Long) oldInstances[i];
+                Long age = _instancesAge.get(id);
+                if (age != null && now-age > BpelDAOConnectionImpl.TIME_TO_LIVE) {
+                    __log.warn("Discarding in-memory instance "+id+" because it exceeded its time-to-live: "+_instances.get(id));
+                    _instances.remove(id);
+                    _instancesAge.remove(id);
+                }
+            }
+        }
     }
 }