org.apache.jcs.engine.memory.shrinking
Class ShrinkerThread

java.lang.Object
  extended by org.apache.jcs.engine.memory.shrinking.ShrinkerThread
All Implemented Interfaces:
Runnable

public class ShrinkerThread
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 783778 2009-06-11 14:11:42Z asmuts $

Constructor Summary
ShrinkerThread(MemoryCache 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(MemoryCache 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. Frist 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 atributes? 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-2012 Apache Software Foundation. All Rights Reserved.