public class Cleanup<K,V> extends Thread
age()
or by running this as a thread.
Identifiable
, CachedObject
> for cachesRetentionPolicy
so that the cleanup knows when to expunge entries (there
are several possible policies and you can have as many as you want, though it is up to you to ensure your
policies make sense.) Start this in its own thread and it will quietly clean up ever so often. To stop the
thread, call the setStopThread(boolean)
to true and the thread will halt as soon as it wakes up.
YOu can also kill the thread directly but generally that can do bad things if the thread is in the middle
of, say, updating you store. Most web servers will wait until all threads exit of their own accord before finishing
a shutdown, incidentally.
Created by Jeff Gaynor
on 7/12/11 at 11:39 AM
Thread.State, Thread.UncaughtExceptionHandler
Modifier and Type | Field and Description |
---|---|
long |
cleanupInterval |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
Cleanup(MyLoggingFacade logger) |
Modifier and Type | Method and Description |
---|---|
void |
addRetentionPolicy(RetentionPolicy retentionPolicy) |
List<V> |
age()
Clean out old entries by aging the elements, i.e., apply the retention policies.
|
long |
getCleanupInterval()
The amount of time, in milliseconds, to wait between attempts to age the cache.
|
Map<K,V> |
getMap() |
List<RetentionPolicy> |
getRetentionPolicies() |
Set<K> |
getSortedKeys()
Return all the keys for the map, sorted into a some order, usually by timestamp.
|
boolean |
isStopThread()
Is this thread set to stop?
|
void |
log(List<V> removed)
Log the results of this.
|
protected void |
log(String x) |
void |
removeRetentionPolicy(RetentionPolicy retentionPolicy) |
void |
run() |
void |
setCleanupInterval(long cleanupInterval) |
void |
setMap(Map<K,V> map) |
void |
setRetentionPolicies(LinkedList<RetentionPolicy> retentionPolicies) |
void |
setStopThread(boolean stopThread)
Sets the flag to stop this thread.
|
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
public Cleanup(MyLoggingFacade logger)
public List<V> age()
public Set<K> getSortedKeys()
public long getCleanupInterval()
public void setCleanupInterval(long cleanupInterval)
public boolean isStopThread()
public void setStopThread(boolean stopThread)
stopThread
- public void addRetentionPolicy(RetentionPolicy retentionPolicy)
public void removeRetentionPolicy(RetentionPolicy retentionPolicy)
public List<RetentionPolicy> getRetentionPolicies()
public void setRetentionPolicies(LinkedList<RetentionPolicy> retentionPolicies)
protected void log(String x)
public void log(List<V> removed)
log(String)
.removed
- Copyright © 2019. All Rights Reserved.