org.apache.jcs.engine.memory.shrinking
Class ShrinkerThread<K extends Serializable,V extends Serializable>

java.lang.Object
  extended by org.apache.jcs.engine.memory.shrinking.ShrinkerThread<K,V>
All Implemented Interfaces:
Runnable

public class ShrinkerThread<K extends Serializable,V extends Serializable>
extends Object
implements Runnable

A background memory shrinker. Memory problems and concurrent modification exception caused by acting directly on an iterator of the underlying memory cache should have been solved.

Version:
$Id: ShrinkerThread.java 1406724 2012-11-07 17:19:03Z tv $

Constructor Summary
ShrinkerThread(IMemoryCache<K,V> cache)
          Constructor for the ShrinkerThread object.
 
Method Summary
protected  boolean checkForRemoval(ICacheElement<?,?> cacheElement, long now)
          Check if either lifetime or idletime has expired for the provided event, and remove it from the cache if so.
 void run()
          Main processing method for the ShrinkerThread object
protected  void shrink()
          This method is called when the thread wakes up.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShrinkerThread

public ShrinkerThread(IMemoryCache<K,V> cache)
Constructor for the ShrinkerThread object.

Parameters:
cache - The MemoryCache which the new shrinker should watch.
Method Detail

run

public void run()
Main processing method for the ShrinkerThread object

Specified by:
run in interface Runnable

shrink

protected void shrink()
This method is called when the thread wakes up. First the method obtains an array of keys for the cache region. It iterates through the keys and tries to get the item from the cache without affecting the last access or position of the item. The item is checked for expiration, the expiration check has 3 parts:
  1. Has the cacheattributes.MaxMemoryIdleTimeSeconds defined for the region been exceeded? If so, the item should be move to disk.
  2. Has the item exceeded MaxLifeSeconds defined in the element attributes? If so, remove it.
  3. Has the item exceeded IdleTime defined in the element attributes? If so, remove it. If there are event listeners registered for the cache element, they will be called.


checkForRemoval

protected boolean checkForRemoval(ICacheElement<?,?> cacheElement,
                                  long now)
                           throws IOException
Check if either lifetime or idletime has expired for the provided event, and remove it from the cache if so.

Parameters:
cacheElement - Element to check for expiration
now - Time to consider expirations relative to. This makes it easier to test.
Returns:
true if the element should be removed, or false.
Throws:
IOException


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.