commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1742934 - in /commons/proper/jcs/trunk: commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/ commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/ src/changes/
Date Mon, 09 May 2016 12:07:32 GMT
Author: tv
Date: Mon May  9 12:07:32 2016
New Revision: 1742934

URL: http://svn.apache.org/viewvc?rev=1742934&view=rev
Log:
Fix JCS-161: Dynamic regions leak memory upon dispose due to ShrinkerTask

Modified:
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCache.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
    commons/proper/jcs/trunk/src/changes/changes.xml

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCache.java?rev=1742934&r1=1742933&r2=1742934&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCache.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/block/BlockDiskCache.java
Mon May  9 12:07:32 2016
@@ -29,6 +29,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
@@ -82,6 +83,8 @@ public class BlockDiskCache<K, V>
      */
     private final ReentrantReadWriteLock storageLock = new ReentrantReadWriteLock();
 
+    private ScheduledFuture<?> future;
+
     /**
      * Constructs the BlockDisk after setting up the root directory.
      * <p>
@@ -167,7 +170,7 @@ public class BlockDiskCache<K, V>
         // TODO we might need to stagger this a bit.
         if ( this.blockDiskCacheAttributes.getKeyPersistenceIntervalSeconds() > 0 )
         {
-            scheduledExecutor.scheduleAtFixedRate(
+            future = scheduledExecutor.scheduleAtFixedRate(
                     new Runnable()
                     {
                         @Override
@@ -585,6 +588,11 @@ public class BlockDiskCache<K, V>
             setAlive(false);
             this.keyStore.saveKeys();
 
+            if (future != null)
+            {
+                future.cancel(true);
+            }
+
             try
             {
                 if ( log.isDebugEnabled() )

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java?rev=1742934&r1=1742933&r2=1742934&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCache.java
Mon May  9 12:07:32 2016
@@ -27,6 +27,7 @@ import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -119,6 +120,8 @@ public class CompositeCache<K, V>
     /** Key matcher used by the getMatching API */
     private IKeyMatcher<K> keyMatcher = new KeyMatcherPatternImpl<K>();
 
+    private ScheduledFuture<?> future;
+
     /**
      * Constructor for the Cache object
      * <p>
@@ -163,7 +166,7 @@ public class CompositeCache<K, V>
     {
         if ( cacheAttr.isUseMemoryShrinker() )
         {
-            scheduledExecutor.scheduleAtFixedRate(
+            future = scheduledExecutor.scheduleAtFixedRate(
                     new ShrinkerThread<K, V>(this), 0, cacheAttr.getShrinkerIntervalSeconds(),
                     TimeUnit.SECONDS);
         }
@@ -1296,6 +1299,12 @@ public class CompositeCache<K, V>
 
         synchronized (this)
         {
+            // Try to stop shrinker thread
+            if (future != null)
+            {
+                future.cancel(true);
+            }
+
             // Now, shut down the event queue
             if (elementEventQ != null)
             {

Modified: commons/proper/jcs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/changes/changes.xml?rev=1742934&r1=1742933&r2=1742934&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/changes/changes.xml (original)
+++ commons/proper/jcs/trunk/src/changes/changes.xml Mon May  9 12:07:32 2016
@@ -20,6 +20,9 @@
 	</properties>
 	<body>
         <release version="2.0" date="unreleased" description="JDK 1.6 based major release">
+            <action issue="JCS-161" dev="tv" type="fix" due-to="Ryan Fong">
+                Fix: Dynamic regions leak memory upon dispose due to ShrinkerTask
+            </action>
             <action issue="JCS-54" dev="tv" type="add" due-to="Tore Halset">
                 Add soft reference memory cache
             </action>



Mime
View raw message