从网上找到的一个quartz的一个例子
来源:互联网 发布:it技术学习 编辑:程序博客网 时间:2024/05/14 03:11
quartz主要是有三部分组成,一个是作业(其实就是一个java类,其中实现了job接口),同时你需要实现execute函数,还有一个就是
trigger,通过此可以设置触发的频率,时间等等,在一个就是调度,就是将以上的两个部分合起来,这样在trigger设置的时间点到来的
时候,触发作业的执行。
import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.quartz.Job;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;public class PrintLog implements Job{public PrintLog() { } public void execute(JobExecutionContext context) throws JobExecutionException { System.out.println("In SimpleQuartzJob - executing its JOB at " + new Date() + " by " + context.getTrigger().getName()); }}
mport java.util.Date;import org.quartz.JobDetail;import org.quartz.Scheduler;import org.quartz.SchedulerFactory;import org.quartz.SimpleTrigger;import org.quartz.impl.StdSchedulerFactory;public class runner { public static void main(String[] args) { runner server = new runner(); SchedulerFactory schedulerFactory = new StdSchedulerFactory(); // Retrieve a scheduler from schedule factory try{ Scheduler scheduler = schedulerFactory.getScheduler(); // current time long ctime = System.currentTimeMillis(); // Initiate JobDetail with job name, job group, and executable job class JobDetail jobDetail = new JobDetail("jobDetail-s1", "jobDetailGroup-s1", PrintLog.class); // Initiate SimpleTrigger with its name and group name SimpleTrigger simpleTrigger = new SimpleTrigger("simpleTrigger", "triggerGroup-s1"); simpleTrigger.setStartTime(new Date(ctime)); // set the interval, how often the job should run (10 seconds here) simpleTrigger.setRepeatInterval(10000); // set the number of execution of this job, set to 10 times. // It will run 10 time and exhaust. simpleTrigger.setRepeatCount(100); // set the ending time of this job. // We set it for 60 seconds from its startup time here // Even if we set its repeat count to 10, // this will stop its process after 6 repeats as it gets it endtime by then. //simpleTrigger.setEndTime(new Date(ctime + 60000L)); // set priority of trigger. If not set, the default is 5 //simpleTrigger.setPriority(10); // schedule a job with JobDetail and Trigger scheduler.scheduleJob(jobDetail, simpleTrigger); // start the scheduler scheduler.start(); }catch(Exception ex){ ex.printStackTrace(); } } }
- 从网上找到的一个quartz的一个例子
- 网上找到 一个关于vpnv4的配置例子
- 从网上找到了一个 读取声音的程序
- 分享网上找到的一个中国象棋源码
- 网上找到一个用不同颜色显示表格奇偶行的例子
- 网上找到一个用不同颜色显示表格奇偶行的例子
- Winform编程总结1—从网上找到一个winform控件,实现打开word的功能
- 网上取数据的一个例子
- 一个网上简单的EJB入门例子
- 关于Quartz一个例子的问题
- 一个quartz如何使用的小例子
- 一个在网上找到的用C++写的游戏
- javascript html 选择保存颜色,从网上找的一个例子
- 网上找到一个解决 zune 连接错误的方法。
- JavaMail例子网上貌似可用的JavaMail例子不多,自己写了一个,以备后用,从QQ发没问题
- 在网上看到的一个关于开闭原则的例子
- 网上摘的一个ListView异步更新图片的例子
- 一个最简单的定时任务Quartz的例子
- 构建全程灾备管理架构
- 快乐
- MySQL常见问题解答
- 二叉查找树
- 使用DELPHI对图片中的文字进行识别的过程(最简单实现)
- 从网上找到的一个quartz的一个例子
- ListCollectionView中filterFunction只对集合过滤一次的实现
- 转的文章,并送给在深圳打拼的人们,有些颓废
- 用于验证码图片识别的类续(C#代码)
- 使用Oracle 11g降低中型企业成本
- 三岁定八十
- 9I管理的V$视图
- java程序员的困惑
- add info to SOAP Header using gSOAP