scheduletask任务调度
1.导入jar包

2.创建entity、
package cn.happy.entity;
public class Plan {
//时间
private String date;
//任务
private String task;
public Plan() {
}
public Plan(String date, String task) {
this.date = date;
this.task = task;
}
@Override
public String toString() {
return "Plan [date=" + date + ", task=" + task + "]";
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
public String getTask() {
return task;
}
public void setTask(String task) {
this.task = task;
}
}
3、创建service
package cn.happy.service; import java.util.ArrayList;
import java.util.List; import cn.happy.entity.Plan; public class RemindService { public void print(String name){
List<Plan> list = getPlan(name);
System.out.println(name+"的提醒信息\n");
for (Plan plan : list) {
System.out.println(plan);
}
}
public void printPlan(String userName){
List<Plan> plansForToday = getPlansForToday(userName);
System.out.print(userName + "的提醒信息:\n");
for(Plan plan:plansForToday){
System.out.print(plan +"\n");
}
} public List<Plan> getPlansForToday(String userName){
//模拟数据库查询,仅为说明问题
List<Plan> list = new ArrayList<Plan>();
list.add(new Plan("2003-8-9 9:00","研讨会 | 地点:会议室C01"));
list.add(new Plan("2003-8-9 14:00","汇报 | 地点:总裁办公室"));
return list;
} public List<Plan> getPlan(String name){
List<Plan> list = new ArrayList<Plan>();
list.add(new Plan("2016年12月18日10:59", "研讨会"));
list.add(new Plan("2016-12-18 11:01","汇报"));
return list;
}
}
4、创建quartz
package cn.happy.quartz; import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException; import cn.happy.service.RemindService;
/**
* 工作调度类 quartz 类 需要实现 job接口
* @author SLEEP
*
*/
public class RemindJob implements Job {
//注入service对象
RemindService service =new RemindService();
@Override
public void execute(JobExecutionContext arg0) throws JobExecutionException {
service.printPlan("见见");
} }
5.创建测试类(关键)
package cn.happy.test; import java.util.Date; import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory; import cn.happy.quartz.RemindJob;
/**
* 测试类
* 使用quartz类
* @author SLEEP
*
*/
public class Test { public void doRemind() throws SchedulerException, InterruptedException { //创建一个任务
JobDetail job= JobBuilder.newJob(RemindJob.class) //
.withIdentity("job1", "group1")
.build();
//创建一个触发器
Trigger trigger = TriggerBuilder.newTrigger()
.withIdentity("myTrigger", "myTriggerGroup")
.withSchedule(SimpleScheduleBuilder.simpleSchedule()
.withIntervalInSeconds(5)
.repeatForever())
.startAt(new Date(System.currentTimeMillis() + 1000))
.build();
//创建调度工厂
SchedulerFactory stdSchedulerFactory = new StdSchedulerFactory();
//创建一个调度者
Scheduler scheduler = stdSchedulerFactory.getScheduler();
//注册并进行调度
scheduler.scheduleJob(job,trigger);
//启动调度
scheduler.start();
//创建调度者工厂
SchedulerFactory sfc = new StdSchedulerFactory();
//创建一个调度者
Scheduler sched = sfc.getScheduler();
//注册并进行调度
sched.scheduleJob(job, trigger);
//启动调度
sched.start();
/*//sleep10s
Thread.sleep(10000);
//关闭调度
sched.shutdown();*/
} /**
*
*/
public static void main(String[] args) {
try{
Test testJob = new Test();
testJob.doRemind();
}catch(Exception e){
e.printStackTrace();
}
}
}
scheduletask任务调度的更多相关文章
- scheduletask任务调度(2间隔时间)
Trigger trigger = TriggerBuilder.newTrigger() .withIdentity("myTrigger", "myTriggerGr ...
- springBoot集成 quartz动态定时任务
项目中需要用到定时任务,考虑了下java方面定时任务无非就三种: 用Java自带的timer类.稍微看了一下,可以实现大部分的指定频率的任务的调度(timer.schedule()),也可以实现关闭和 ...
- Spring任务调度
任务调度是大多数应用系统的常见需求之一,拿论坛来说:每个半个小时生成精华文章的RSS文件,每天凌晨统计论坛用户的积分排名,每隔30分钟执行对锁定过期的用户进行解锁.以上都是以时间为关注点的调度,事实上 ...
- SpringBoot2 task scheduler 定时任务调度器四种方式
github:https://github.com/chenyingjun/springboot2-task 使用@EnableScheduling方式 @Component @Configurabl ...
- java实现任务调度
最近的一个小项目是做一个简单的数据仓库,需要将其他数据库的数据抽取出来,并通过而出抽取成页面需要的数据,以空间换时间的方式,让后端报表查询更快. 因为在抽取的过程中,有一定的先后顺序,需要做一个任务调 ...
- .net 分布式架构之任务调度平台
开源地址:http://git.oschina.net/chejiangyi/Dyd.BaseService.TaskManager .net 任务调度平台 用于.net dll,exe的任务的挂载, ...
- 免费开源的DotNet任务调度组件Quartz.NET(.NET组件介绍之五)
很多的软件项目中都会使用到定时任务.定时轮询数据库同步,定时邮件通知等功能..NET Framework具有“内置”定时器功能,通过System.Timers.Timer类.在使用Timer类需要面对 ...
- Spring Quartz实现任务调度
任务调度 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情 核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作 任务调度涉及多线程并发.线程池维 ...
- Quartz实现任务调度
一.任务调度概述 在企业级应用中,经常会制定一些"计划任务",即在某个时间点做某件事情,核心是以时间为关注点,即在一个特定的时间点,系统执行指定的一个操作,任务调度涉及多线程并发. ...
随机推荐
- IIS7禁用单个静态文件的缓存配置方法
IIS7中,想将一个经常修改的静态文件设置为不可缓存,在IIS配置界面里怎么也找不到... 一番google之后在stackoverflow里边发现了这样一段回答,最终解决了问题: just stum ...
- Node.js:console模块
console模块提供了一个简单的调试功能,类似与web浏览器的javscript console. 下面简单介绍下该模块的使用以及用途,我使用了ES6的模版字符串(使用反引号标识),有兴趣的可以去了 ...
- Set容器--HashSet集合
Set容器特点: ① Set容器是一个不包含重复元素的Collection,并且最多包含一个null元素,它和List容器相反,Set容器不能保证其元素的顺序; ② 最常用的两个Set接口的实 ...
- 无限循环轮播图之JS部分(原生JS)
JS逻辑与框架调用, <script type="text/javascript"> var oBox = document.getElementById('box') ...
- Spark的DataFrame的窗口函数使用
作者:Syn良子 出处:http://www.cnblogs.com/cssdongl 转载请注明出处 SparkSQL这块儿从1.4开始支持了很多的窗口分析函数,像row_number这些,平时写程 ...
- HTML5 网络拓扑图整合 OpenLayers 实现 GIS 地图应用
在前面<百度地图.ECharts整合HT for Web网络拓扑图应用>我们有介绍百度地图和 HT for Web 的整合,我们今天来谈谈 OpenLayers 和 HT for Web ...
- UED双飞翼布局
<style> body,html { height:%; padding: ; margin: } .main { background: #f2f2f2; width: %; floa ...
- BaaS API 设计规范
上个月写了一个团队中的 BaaS API 的设计规范,给大家分享下: 目录 1. 引言... 4 1.1. 概要... 4 1.2. 参考资料... 4 1.3. 阅读对象... 4 1.4. 术语解 ...
- asp.net core 简单部署之FTP配置(CentOS 7.0安装配置Vsftp服务器)
配置过程原文地址:http://www.osyunwei.com/archives/9006.html 坑和结果 正确的跟着这个内容走,是靠谱的. 我自己给自己踩了个坑,请参照文章的朋友注意第七条:七 ...
- 十五天精通WCF——第一天 三种Binding让你KO80%的业务
转眼wcf技术已经出现很多年了,也在.net界混的风生水起,同时.net也是一个高度封装的框架,作为在wcf食物链最顶端的我们所能做的任务已经简单的不能再简单了, 再简单的话马路上的大妈也能写wcf了 ...