All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.data.exploration.biz.quartz.JobScheduler Maven / Gradle / Ivy

The newest version!
package com.datastax.data.exploration.biz.quartz;

import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.springframework.stereotype.Component;

import static org.quartz.CronScheduleBuilder.cronSchedule;

/**
 * 定时删文件任务 放到com.datastax.insight.webapp.listener.ContextRefreshedListener调用
 */
@Component
public class JobScheduler {

    @Autowired
    SchedulerFactoryBean schedulerFactoryBean;

    public void schedulerJobs() throws SchedulerException {
        Scheduler scheduler = schedulerFactoryBean.getScheduler();
        startDeleteTimerJob(scheduler);
    }

    public void startDeleteTimerJob(Scheduler scheduler) throws SchedulerException {

        //触发时间点
        CronScheduleBuilder cronScheduleBuilder = cronSchedule("0 0 3 * * ?");// 每天凌晨3点执行一次任务
//        CronScheduleBuilder cronScheduleBuilder = cronSchedule("0/5 * * * * ?"); //每5秒执行一次
        //定义一个Trigger
        Trigger trigger = TriggerBuilder.newTrigger()
                .withIdentity("triggerDelete","groupExploration")
                .startNow()
                .withSchedule(cronScheduleBuilder)
                .build();
        //具体任务.
        JobDetail jobDetail=JobBuilder
                .newJob(DeleteTimerJob.class)
                .withIdentity("jobDetele","groupExploration")
                .build();
        //加入这个调度
        scheduler.scheduleJob(jobDetail, trigger);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy