java调度quartz_java 使用Quartz定时任务调度

import org.quartz.CronTrigger;

import org.quartz.JobDetail;

import org.quartz.Scheduler;

import org.quartz.SchedulerFactory;

import org.quartz.impl.StdSchedulerFactory;

public abstract class AbstractExpSched {

/**

* 设置调度任务启动参数

* @param cls 启动任务类名称

* @param cronExpression 启动表达式

* @param taskName 任务名称

* @throws Exception

*/

public void set(Class> cls,String cronExpression,String taskName,String job)throws Exception{

//SchedulerFactory 提供一种获取调度程序实例的机制

SchedulerFactory schedFact = new StdSchedulerFactory();

//获取调度程序

Scheduler sched = schedFact.getScheduler();

//Conveys the detail properties of a given Job instance.new JobDetail(String name, String group, Class jobClass)

JobDetail jobDetailStand = new JobDetail(job, "expGroup",cls);

//Get the JobDataMap that is associated with the Job.

jobDetailStand.getJobDataMap().put("name", taskName);

//A concrete Trigger that is used to fire a JobDetail at given moments in time, defined with Unix 'cron-like' definitions.

CronTrigger triggerStand = new CronTrigger(taskName, "expGroup");

//设置定时机制cronExpression如:"0 0 12 * * ?"

triggerStand.setCronExpression(cronExpression);

// Add the given JobDetail to the Scheduler, and associate the given Trigger with it.

sched.scheduleJob(jobDetailStand, triggerStand);

sched.start();

}

public abstract void start();

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值