首页>代码>基于SpringBoot+Vue实现的电影院售票系统>/最代码/服务端/CinemaManagerApi - idea/src/main/java/com/rabbiter/cm/common/config/QuartzConfig.java
package com.rabbiter.cm.common.config;


import com.rabbiter.cm.common.utils.ApplicationContextUtils;
import com.rabbiter.cm.service.impl.SysBillServiceImpl;
import com.rabbiter.cm.service.impl.SysSessionServiceImpl;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

@Configuration
public class QuartzConfig {

    @Autowired
    private SysBillServiceImpl sysBillService;

    @Autowired
    private SysSessionServiceImpl sysSessionService;

    @Bean
    public JobDetail jobDetail() {
        QuartzJobBean quartzJob = new QuartzJobBean() {
            @Override
            protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                System.out.println("执行取消超时订单处理" + sdf.format(new Date()));
                // 取消所有超时订单并释放占座资源
                ApplicationContextUtils.getBean("cancelTimeoutBill");
            }
        };
        return JobBuilder.newJob(quartzJob.getClass()).storeDurably().build();
    }

    @Bean
    public SimpleTrigger trigger() {
        //每5分钟执行一次,一直重复执行
        SimpleScheduleBuilder scheduleBuilder =
                SimpleScheduleBuilder.simpleSchedule()
                        .withIntervalInSeconds(5 * 60)
                        .repeatForever();
        return TriggerBuilder.newTrigger()
                .forJob(jobDetail())
                .withSchedule(scheduleBuilder).build();
    }

}
最近下载更多
dddding yang  LV6 9月15日
C544350851  LV27 6月10日
陈小灏  LV18 2月18日
oceanchen  LV14 2024年10月30日
hanyuelinmumu  LV4 2024年10月28日
xp95323  LV15 2024年10月10日
微信网友_7177544545669120  LV1 2024年9月21日
java小书童  LV18 2024年6月6日
sadselect  LV8 2024年5月18日
wangyuqi20020721  LV2 2024年4月27日
最近浏览更多
khmumuno 昨天
暂无贡献等级
dddding yang  LV6 9月15日
康日澜  LV10 8月3日
熙熙_123 6月20日
暂无贡献等级
C544350851  LV27 6月10日
bwxh66 6月10日
暂无贡献等级
lkke23047  LV1 5月26日
梁小贤  LV1 5月22日
999772 5月7日
暂无贡献等级
Liu_Lian 4月3日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友