asmuts 2004/05/09 18:17:08
Modified: src/java/org/apache/jcs/engine/memory/shrinking
ShrinkerThread.java
Log:
added a maximum number to spool per run for the shrinker.
Revision Changes Path
1.12 +39 -2
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java
Index: ShrinkerThread.java
===================================================================
RCS file:
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory/shrinking/ShrinkerThread.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- ShrinkerThread.java 15 Apr 2004 19:22:50 -0000 1.11
+++ ShrinkerThread.java 10 May 2004 01:17:08 -0000 1.12
@@ -53,6 +53,10 @@
/** Maximum memory idle time for the whole cache */
private final long maxMemoryIdleTime;
+ /** Maximum number of items to spool per run. Default is -1, or no limit. */
+ private int maxSpoolPerRun;
+ private boolean spoolLimit = false;
+
/** Flag that indicates if the thread is still alive */
boolean alive = true;
@@ -81,6 +85,14 @@
{
this.maxMemoryIdleTime = maxMemoryIdleTimeSeconds * 1000;
}
+
+ this.maxSpoolPerRun =
+ cache.getCacheAttributes().getMaxSpoolPerRun();
+ if ( this.maxSpoolPerRun != -1 )
+ {
+ this.spoolLimit = true;
+ }
+
}
/**
@@ -151,11 +163,17 @@
{
Object[] keys = cache.getKeyArray();
int size = keys.length;
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "Keys size: " + size );
+ }
Serializable key;
ICacheElement cacheElement;
IElementAttributes attributes;
+ int spoolCount = 0;
+
for ( int i = 0; i < size; i++ )
{
key = ( Serializable ) keys[ i ];
@@ -201,6 +219,9 @@
if ( !remove && ( maxMemoryIdleTime != -1 ) )
{
+ if ( !spoolLimit || (spoolCount <= this.maxSpoolPerRun) )
+ {
+
final long lastAccessTime = attributes.getLastAccessTime();
if ( lastAccessTime + maxMemoryIdleTime < now )
@@ -214,13 +235,29 @@
// FIXME: Shouldn't we ensure that the element is
// spooled before removing it from memory?
+ spoolCount++;
+
cache.remove( cacheElement.getKey() );
cache.waterfal( cacheElement );
+
+ key = null;
+ cacheElement = null;
}
+ }
+ else
+ {
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( "spoolCount = '" + spoolCount + "'; " +
+ "maxSpoolPerRun = '" + maxSpoolPerRun + "'");
+ }
+ }
}
-
}
+
+ keys = null;
+ System.gc();
}
catch ( Throwable t )
{
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]