Quartz[时间任务]之Jfinal
来源:互联网 发布:东方财富mac上线 编辑:程序博客网 时间:2024/06/03 00:00
1.导入jar包:
下载地址:http://grepcode.com/snapshot/repo1.maven.org/maven2/org.quartz-scheduler/quartz/1.7.3
2.在服务器启动的所加载的文件配置你的Quartz
Config.java的configPlugin()方法中
me.add(new QuartzPlugin());你的Quartz的类
3.在job.properties文件中配置任务的参数
crawler.job=com.coo.crawlerJob.java#######你的所需要执行的任务类:crawler.cron=0 20 16 * * ?#########时间参数,表示时间16:20执行你的任务crawler.enable=true
4.QuartzPlugin.java
package com.fosbd.plugins;import com.fosbd.kit.ReflectKit;import com.jfinal.log.Logger;import com.jfinal.plugin.IPlugin;import org.quartz.*;import org.quartz.impl.StdSchedulerFactory;import java.io.IOException;import java.io.InputStream;import java.util.Enumeration;import java.util.Properties;/** * modify by Jfinal-ext */public class QuartzPlugin implements IPlugin{ private static final String JOB = "job"; private final Logger logger = Logger.getLogger(getClass()); private SchedulerFactory sf; private Scheduler sched; private String config = "job.properties"; private Properties properties; public QuartzPlugin(String config) { this.config = config; } public QuartzPlugin() { } @Override public boolean start() { sf = new StdSchedulerFactory(); try { sched = sf.getScheduler(); } catch (SchedulerException e) { e.printStackTrace(); } loadProperties(); Enumeration<Object> enums = properties.keys(); while (enums.hasMoreElements()) { String key = enums.nextElement() + ""; if (!key.endsWith(JOB) || !isEnableJob(enable(key))) { continue; } String jobClassName = properties.get(key) + ""; String jobCronExp = properties.getProperty(cronKey(key)) + ""; Class<Job> clazz = ReflectKit.on(jobClassName).get(); JobDetail job = JobBuilder.newJob(clazz) .withIdentity(jobClassName,jobClassName) .build(); CronTrigger trigger = TriggerBuilder.newTrigger() .withIdentity(jobClassName,jobClassName) .withSchedule(CronScheduleBuilder.cronSchedule(jobCronExp)) .build(); java.util.Date ft = null; try { ft = sched.scheduleJob(job, trigger); sched.start(); } catch (SchedulerException e) { e.printStackTrace(); } logger.debug(job.getKey() + " has been scheduled to run at: " + ft + " and repeat based on expression: " + trigger.getCronExpression()); } return true; } @Override public boolean stop() { try { sched.shutdown(); } catch (SchedulerException e) { e.printStackTrace(); } return true; } private String enable(String key) { return key.substring(0, key.lastIndexOf(JOB)) + "enable"; } private String cronKey(String key) { return key.substring(0, key.lastIndexOf(JOB)) + "cron"; } private boolean isEnableJob(String enableKey) { Object enable = properties.get(enableKey); if (enable != null && "false".equalsIgnoreCase((enable + "").trim())) { return false; } return true; } private void loadProperties() { properties = new Properties(); InputStream is = QuartzPlugin.class.getClassLoader().getResourceAsStream(config); try { properties.load(is); } catch (IOException e) { e.printStackTrace(); } logger.debug("------------load Propteries---------------"); logger.debug(properties.toString()); logger.debug("------------------------------------------"); }}
5.crawlerJob.java
package com.fosbd.job;import com.fosbd.model.InfoEn;import com.fosbd.util.JsoupUtil;import com.jfinal.log.Logger;import org.quartz.Job;import org.quartz.JobExecutionContext;import org.quartz.JobExecutionException;import java.util.List;/** * Created by pc on 2015/4/22. */public class crawlerJob implements Job { private static Logger logger = Logger.getLogger(crawlerJob.class); @Override public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException { //编写你要定时的任务代码 }}
0 0
- Quartz[时间任务]之Jfinal
- jfinal+quartz定时任务
- jfinal任务调度quartz(cron)
- JFinal+Quartz动态任务调度控制台
- JFinal+Quartz动态任务调度控制台
- quartz定时任务时间设置
- Quartz任务调度 时间设置
- Quartz 定时任务 时间配置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- quartz定时任务时间设置
- uvalive2222(等差序列前n项求和)
- 银联在线支付----测试商户账号注册
- MySQL存储过程之事务管理
- bitmap与base64之间的转换
- oracle分区+分区索引+函数索引
- Quartz[时间任务]之Jfinal
- 安卓横竖屏切换的处理方式
- python基础
- LOADRUNNER中PACING的设置
- 未能加载文件或程序集“Microsoft.SqlServer.Sqm, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc
- 去掉navigationbar下面的一条黑线
- Activity启动模式
- linux 脚本编写
- 地图编辑器