• 定时任务(一)


    package com.sf.dangbao.core.TimeTask;

    import cn.hutool.core.date.DateUtil;
    import com.sf.dangbao.core.service.DistributionTaskService;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    import org.quartz.DisallowConcurrentExecution;
    import org.quartz.JobExecutionContext;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.scheduling.quartz.QuartzJobBean;

    @DisallowConcurrentExecution
    public class DistributeTaskJob extends QuartzJobBean {
    private static Logger LOGGER = LogManager.getLogger(DistributeTaskJob.class);

    @Autowired
    private DistributionTaskService distributionTaskService;

    /**
    * 凌晨四点创建今日的配送任务
    * @param jobExecutionContext
    */
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
    long start = System.currentTimeMillis();
    LOGGER.info("开始生成今日配送任务");
    String today = DateUtil.today();
    distributionTaskService.createTask(today);
    long internal = System.currentTimeMillis() - start;
    LOGGER.info("生成今日配送任务完成,耗时:{}", internal);
    }
    }



    —————————————————————————————————————

    package com.sf.dangbao.core.TimeTask;

    import cn.hutool.core.date.DateUtil;
    import com.sf.dangbao.core.service.DistributionTaskService;
    import org.apache.logging.log4j.LogManager;
    import org.apache.logging.log4j.Logger;
    import org.quartz.DisallowConcurrentExecution;
    import org.quartz.JobExecutionContext;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.scheduling.quartz.QuartzJobBean;

    @DisallowConcurrentExecution
    public class TomorrowTaskJob extends QuartzJobBean {
    private static Logger LOGGER = LogManager.getLogger(DistributeTaskJob.class);

    @Autowired
    private DistributionTaskService distributionTaskService;

    /**
    * 晚上九点创建明日的配送任务
    * @param jobExecutionContext
    */
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {
    long start = System.currentTimeMillis();
    LOGGER.info("开始生成明日配送任务");
    String tomorrow = DateUtil.format(DateUtil.tomorrow(),"yyyy-MM-dd");
    distributionTaskService.createTask(tomorrow);
    long internal = System.currentTimeMillis() - start;
    LOGGER.info("生成明日配送任务完成,耗时:{}", internal);
    }
    }
  • 相关阅读:
    第六次作业--结对编程第二次
    OneZero第四周第三次站立会议(2016.4.13)
    结对编程体会2
    OneZero第四周第二次站立会议(2016.4.12)
    关于“单元测试工具”
    OneZero第四周第一次站立会议(2016.4.11)
    OneZero第四周——预完成功能点统计
    OneZero第三周第五次站立会议(2016.4.8)
    OneZero第三周第四次站立会议(2016.4.7)
    OneZero第三周第三次站立会议(2016.4.6)
  • 原文地址:https://www.cnblogs.com/pxzbky/p/11911288.html
Copyright © 2020-2023  润新知