Package org.shiftone.cache.util.reaper

Source Code of org.shiftone.cache.util.reaper.ReaperTask

package org.shiftone.cache.util.reaper;



import org.shiftone.cache.util.Log;

import java.lang.ref.SoftReference;
import java.util.TimerTask;


/**
* Class ReaperTask
*
*
* @author <a href="mailto:jeff@shiftone.org">Jeff Drost</a>
* @version $Revision: 1.2 $
*/
public class ReaperTask extends TimerTask
{

    private static final Log  LOG             = new Log(ReaperTask.class);
    private static long       instanceCounter = 0;
    private static final long instanceNumber  = (instanceCounter++);
    private SoftReference     reference       = null;
    private String            toString;

    public ReaperTask(ReapableCache cache)
    {
        this.toString  = cache.toString();
        this.reference = new SoftReference(cache);
    }


    public void run()
    {

        ReapableCache reapableCache = (ReapableCache) reference.get();
        String        threadName    = Thread.currentThread().getName();

        Thread.currentThread().setName("REAPER for " + instanceNumber);
        LOG.debug("run");

        if (reapableCache == null)
        {
            LOG.info("cache reaper quitting for : " + toString + " #" + instanceNumber);
            cancel();
        }
        else
        {
            reapableCache.removeExpiredElements();
        }

        Thread.currentThread().setName(threadName);
    }
}
TOP

Related Classes of org.shiftone.cache.util.reaper.ReaperTask

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.