01: package org.shiftone.cache.util.reaper;
02:
03: import org.shiftone.cache.util.Log;
04:
05: import java.lang.ref.SoftReference;
06: import java.util.TimerTask;
07:
08: /**
09: * Class ReaperTask
10: *
11: *
12: * @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
13: * @version $Revision: 1.2 $
14: */
15: public class ReaperTask extends TimerTask {
16:
17: private static final Log LOG = new Log(ReaperTask.class);
18: private static long instanceCounter = 0;
19: private static final long instanceNumber = (instanceCounter++);
20: private SoftReference reference = null;
21: private String toString;
22:
23: public ReaperTask(ReapableCache cache) {
24: this .toString = cache.toString();
25: this .reference = new SoftReference(cache);
26: }
27:
28: public void run() {
29:
30: ReapableCache reapableCache = (ReapableCache) reference.get();
31: String threadName = Thread.currentThread().getName();
32:
33: Thread.currentThread().setName("REAPER for " + instanceNumber);
34: LOG.debug("run");
35:
36: if (reapableCache == null) {
37: LOG.info("cache reaper quitting for : " + toString + " #"
38: + instanceNumber);
39: cancel();
40: } else {
41: reapableCache.removeExpiredElements();
42: }
43:
44: Thread.currentThread().setName(threadName);
45: }
46: }
|