CacheCleanJob.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package com.yihu.wlyy.statistics.job.cache;
  2. import com.yihu.wlyy.statistics.etl.mycache.CachePool;
  3. import com.yihu.wlyy.statistics.etl.storage.DBStorage;
  4. import com.yihu.wlyy.statistics.model.job.QuartzJobLog;
  5. import org.quartz.Job;
  6. import org.quartz.JobExecutionContext;
  7. import org.quartz.JobExecutionException;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.context.annotation.Scope;
  10. import org.springframework.stereotype.Component;
  11. import java.text.SimpleDateFormat;
  12. import java.util.Date;
  13. /**
  14. * Created by Administrator on 2016.10.19.
  15. */
  16. @Component
  17. @Scope("prototype")
  18. public class CacheCleanJob implements Job {
  19. public static String jobKey="CLEAN_CACHE_JOB";
  20. public static String cron="0 55 23 * * ?";
  21. @Autowired
  22. private DBStorage dbStorage;
  23. @Override
  24. public void execute(JobExecutionContext context) throws JobExecutionException {
  25. QuartzJobLog quartzJobLog = new QuartzJobLog();
  26. quartzJobLog.setJobStartTime(new Date());
  27. quartzJobLog.setJobId(jobKey);
  28. quartzJobLog.setJobName(jobKey);
  29. CachePool.cleanAllCache();
  30. quartzJobLog.setJobEndTime(new Date());
  31. quartzJobLog.setJobContent("清空缓存成功:"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
  32. quartzJobLog.setJobType("1");
  33. dbStorage.saveLog(quartzJobLog);
  34. }
  35. }