定时任务需要执行的工作:
PrintInfoJob.class
public class PrintInfoJob implements Job{
public PrintInfoJob(){}
/**
* Test Job == Print Job Name + Execute Time
* @param context
* @throws JobExecutionException
*/
public void execute(JobExecutionContext context)throws JobExecutionException{
System.out.println("PrintInfoJob executing... Date : " + new Date());
}
}
定制任务,使用 AnnualCalender 来排除银行节日(即:在某段时间,不指定定时任务的工作)
TestAnnualCalender.class
/**
* 使用AnnualCalender来排除银行节目
* @name TestAnnualCalender.java
* @author vivi
* @time 2009-9-3 上午09:20:43
*/
public class TestAnnualCalender {
static Log logger = LogFactory.getLog(TestAnnualCalender.class);
public static void main(String[] args) {
TestAnnualCalender example = new TestAnnualCalender();
example.startScheduler();
}
public void startScheduler(){
try{
//create and start the scheduler
Scheduler scheduler = StdSchedulerFactory.getDefaultScheduler();
scheduler.start();
scheduleJob(scheduler, PrintInfoJob.class);
logger.info("Scheduler starting up ... ...");
}catch(SchedulerException e){
logger.error(e);
}
}
private void scheduleJob(Scheduler scheduler, Class jobClass){
try{
//Create an instance of the Quartz AnnualCalendar
AnnualCalendar cal = new AnnualCalendar();
//exclude July 4th
Calendar gCal = GregorianCalendar.getInstance();
gCal.set(Calendar.MONTH, Calendar.JULY);
gCal.set(Calendar.DATE, 4);
cal.setDayExcluded(gCal, true);
//add to scheduler .replace existing, update triggers
scheduler.addCalendar("bankHolidays", cal, true, true);
/*
* Set up a trigger to start firing now, repeat forever
* and have (60000 ms) between each firing.
*/
Trigger trigger = org.quartz.TriggerUtils.makeImmediateTrigger("myTrigger", -1, 3000);
//trigger will use Calendar to exclude firing times
trigger.setCalendarName("bankHolidays");
JobDetail jobDetail = new JobDetail(jobClass.getName(),
Scheduler.DEFAULT_GROUP, jobClass);
//associate the trigger with the job in the scheduler
scheduler.scheduleJob(jobDetail, trigger);
}catch(SchedulerException ex){
logger.error(ex);
}
}
}
分享到:
相关推荐
kratos定时任务-kratos-cron
在数据库中实现定时任务-详解及实例.pdf
不使用数据库动态设置定时任务-celery_demo
定时启动任务--跟随web容器启动,定时启动任务--跟随web容器启动
定时任务--实现步骤、操作手册操作手册新增执行器AppName:自定义名称:自定义排序:自定义,不能重复注册方式:自动注册—应该为读取配置文件中的配置信息中的机
定时任务-scheduler_JOB.sql
Quartz实现.Net Core项目定时任务-实例
基于多进程的定时任务管理器,支持秒级别的定时任务-php_crond
另一个浙大健康打卡定时任务-ZJU_healthreport
Spring Boot实现动态增加、删除、修改、停止定时任务-dynamicScheduler
NULL 博文链接:https://liangjian103.iteye.com/blog/1141253
一个测试工具,定时任务相关的。采用 springboot和quartz结合的方式,实现前台控制后台的定时任务。可以新增/删除/修改/启动/暂停/查询后台定时任务。
定时关机-测试可以使用。定时关机-测试可以使用。
分布式定时任务elastic-job 。 自己写的一个例子, 项目小但是经过测试,已经包含所有的功能。 项目是maven项目,导入eclipse中 下载jar包, 运行里边的 main方法,即可运行。 部署在多台服务器时,需要zookeeper...
1_什么事定时任务.mp4 2_为什么学习定时任务.mp4 3_定时任务技术发展趋势.mp4 4_主流定时任务框架优缺点和什么是分布式定时任务.mp4 5_环境搭建总体流程.mp4 6_前期准备-JDK.mp4 7_前期准备-Maven.mp4 8_前期准备-...
分布式定时任务库 distributed-cron
plsql创建存储过程并创建job定时任务执行-详细笔记文档总结
java定时任务代码-spring管理.txtjava定时任务代码-spring管理.txtjava定时任务代码-spring管理.txt
NULL 博文链接:https://pouyang.iteye.com/blog/621360
Springboot中使用数据库配置定时任务,并在Job中自动装配Spring容器Bean。