public class StoreJanitorImpl extends org.apache.avalon.framework.logger.AbstractLogEnabled implements StoreJanitor, org.apache.avalon.framework.parameters.Parameterizable, org.apache.avalon.framework.thread.ThreadSafe, java.lang.Runnable, org.apache.avalon.framework.activity.Startable
A few parameters can be used:
cleanupthreadinterval defines the maximum
cleanup interval. Cleanup interval then is determined based on the
memory fill rate: the faster memory is filled in, and the less free
memory is left, the shorter is the cleanup time.| Modifier and Type | Field and Description |
|---|---|
private boolean |
adaptiveThreadInterval |
private boolean |
doRun |
private boolean |
firstRun
Flag to ignore memory bursts during startup (1st janitor run)
|
private double |
fraction |
private int |
index |
protected long |
interval
The calculated delay for the next checker run in ms
|
protected long |
inUse
Amount of memory in use before sleep().
|
protected boolean |
invokeGC
Should the gc be called on low memory?
|
private java.lang.Runtime |
jvm |
private int |
maxHeapSize |
private long |
maxRateOfChange
Used memory change rate in bytes per second
|
private int |
minFreeMemory |
private int |
minThreadInterval |
private int |
priority |
private boolean |
secondRun
Flag to ignore memory bursts during startup (2nd janitor run)
|
private java.util.ArrayList |
storelist |
private int |
threadInterval |
ROLE| Constructor and Description |
|---|
StoreJanitorImpl() |
| Modifier and Type | Method and Description |
|---|---|
private int |
calcToFree(Store store)
This method claculates the number of Elements to be freememory
out of the Cache.
|
protected void |
checkMemory()
The "checker" thread checks if memory is running low in the jvm.
|
private void |
freeMemory()
Round Robin alghorithm for freeing the registered caches.
|
private void |
freePhysicalMemory()
This method forces the garbage collector
|
private boolean |
getAdaptiveThreadInterval() |
private int |
getIndex() |
private java.lang.Runtime |
getJVM() |
private int |
getMaxHeapSize() |
private int |
getMinFreeMemory() |
private int |
getPriority() |
private java.util.ArrayList |
getStoreList() |
private int |
getThreadInterval() |
java.util.Iterator |
iterator()
This method return a java.util.Iterator of every registered stores
The iterators returned is fail-fast: if list is structurally
modified at any time after the iterator is created, in any way, the
iterator will throw a ConcurrentModificationException.
|
private long |
longDiv(long top,
long bottom) |
protected long |
memoryInUse()
Calculate the JVM memory in use now.
|
private boolean |
memoryLow()
Method to check if memory is running low in the JVM.
|
private long |
minTimeToFill(long rate)
Calculate amount of time needed to fill all free memory with given
fill rate.
|
void |
parameterize(org.apache.avalon.framework.parameters.Parameters params)
Parameterize the StoreJanitorImpl.
|
void |
register(Store store)
This method register the stores
|
void |
run()
The "checker" thread loop.
|
private void |
setIndex(int _index) |
void |
start() |
void |
stop() |
void |
unregister(Store store)
This method unregister the stores
|
private int minFreeMemory
private int maxHeapSize
private int threadInterval
private int minThreadInterval
private boolean adaptiveThreadInterval
private int priority
private double fraction
protected boolean invokeGC
private java.lang.Runtime jvm
private java.util.ArrayList storelist
private int index
private boolean doRun
protected long inUse
memoryInUse()private boolean firstRun
private boolean secondRun
protected long interval
private long maxRateOfChange
public void parameterize(org.apache.avalon.framework.parameters.Parameters params)
throws org.apache.avalon.framework.parameters.ParameterException
parameterize in interface org.apache.avalon.framework.parameters.Parameterizableparams - the Configuration of the applicationorg.apache.avalon.framework.parameters.ParameterExceptionpublic void start()
start in interface org.apache.avalon.framework.activity.Startablepublic void stop()
stop in interface org.apache.avalon.framework.activity.Startablepublic void run()
run in interface java.lang.Runnableprotected void checkMemory()
private boolean memoryLow()
protected long memoryInUse()
private long minTimeToFill(long rate)
rate - memory fill rate in time per bytesprivate long longDiv(long top,
long bottom)
public void register(Store store)
register in interface StoreJanitorstore - the store to be registeredpublic void unregister(Store store)
unregister in interface StoreJanitorstore - the store to be unregisteredpublic java.util.Iterator iterator()
iterator in interface StoreJanitorprivate void freeMemory()
private int calcToFree(Store store)
store - the Store which was selected as victimprivate void freePhysicalMemory()
private int getMinFreeMemory()
private int getMaxHeapSize()
private int getPriority()
private int getThreadInterval()
private boolean getAdaptiveThreadInterval()
private java.lang.Runtime getJVM()
private java.util.ArrayList getStoreList()
private void setIndex(int _index)
private int getIndex()