-------------------------------------------CODE HERE-----------------------------------------------------------
package com.tian.rates.cache; import java.io.Serializable; import java.util.List; import java.util.Map; import net.sf.ehcache.Cache; import net.sf.ehcache.Element; import org.aspectj.lang.ProceedingJoinPoint; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import org.springframework.scheduling.quartz.QuartzJobBean;
public class CacheRefreshQuartz extends QuartzJobBean{ private Cache cache; public void setCache(Cache cache) { this.cache = cache; } @SuppressWarnings("unchecked") protected void executeInternal(JobExecutionContext ctx) throws JobExecutionException { // do the actual work System.out.println("Begin QuartzJob."); List list = cache.getKeys(); for (Object s : list) { System.out.println("Begin refresh the cache.--->" + s); Element element = cache.get(s); Map map = (Map) element.getValue(); Object result = null; ProceedingJoinPoint joinPoint = (ProceedingJoinPoint) map.get("invocation"); try { result = joinPoint.proceed(); } catch (Throwable e) { e.printStackTrace(); } if (result != null) { map.remove("result"); map.put("result", (Serializable) result); } System.out.println("Ending refresh the cache.--->" + s); } System.out.println("Ending QuartzJob."); } }