基于quartz-2.1.3.jar 的quartz调度表达式
来源:互联网 发布:王诺诺知乎女神扒皮 编辑:程序博客网 时间:2024/05/18 06:38
下载 quartz-2.1.3.jar 下载地址 http://download.csdn.net/download/chenshijie2011/10129927
1 . springmvc-servlet.xml 配置文件
<!--定义定时执行QuartTimer这个bean中的quartTimerMethod()方法 --><bean id="doJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean"> <!--你要执行的那个方法对应的bean --> <property name="targetObject"> <ref bean="QuartTimer" /> </property> <!--你要执行那个方法,注意方法不能有返回值,参数好像也不能有 --> <property name="targetMethod"> <value>quartTimerMethod</value> </property> <property name="concurrent" value="false" /> </bean> <!--触发器的bean的设置,在这里我们设置了我们要触发的jobDetail是哪个。 这里我们定义了要触发的jobDetail是searchEngerneTask,即触发器去触发哪个bean。 并且我们还定义了触发的时间。 spring版本<3.1,quartz版本为1.x,class使用CronTriggerBean; spring版本>3.1,quartz版本为2.x,class使用CronTriggerFactoryBean;尽量按这两种方式使用--> <bean id="cronTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean"> <property name="jobDetail"> <ref bean="doJob" /> </property> <property name="cronExpression"> <!-- 执行周期的表达式;每小时:[0 0 * * * ?]; 每五钟:[0 0/5 * * * ?]--> <value>0 10 0 * * ?</value><!-- 每天0点10分执行一次 --> </property> </bean> <!--管理触发器的总设置,管理我们的触发器列表,可以在bean的list中放置多个触发器。 --> <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean" lazy-init="false" > <property name="triggers"> <list> <ref bean="cronTrigger" /> </list> </property> <property name="configLocation" value="classpath:config/quartz.properties"/> </bean>
- quartz 配置文件 quartz.properties
org.quartz.scheduler.instanceName: DefaultQuartzSchedulerorg.quartz.scheduler.rmi.export: falseorg.quartz.scheduler.rmi.proxy: falseorg.quartz.scheduler.wrapJobExecutionInUserTransaction: falseorg.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPoolorg.quartz.threadPool.threadCount: 1org.quartz.threadPool.threadPriority: 5org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: trueorg.quartz.jobStore.misfireThreshold: 60000org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
- package com.*.quartz 为调用包,QuartTimer 为定时器类
package com.***.quartz;import java.io.BufferedReader;import java.io.InputStreamReader;import org.springframework.context.annotation.Lazy;import org.springframework.stereotype.Component;import org.springframework.stereotype.Service;import com.cetiti.dim.common.ScheduleConfig;/** * 测试定时器 */@Component("QuartTimer")@Lazy(false)public class QuartTimer { /** * @Date 创建时间:2016年8月9日 下午4:47:05 * @Description :定时作业执行 */ public void quartTimerMethod(){ System.out.println("testQuartTimerMethod 1111111111 定时作业执行中..."); this.runShell(); System.out.println("testQuartTimerMethod 2222222222 定时作业执行中..."); } public void runShell(){ try { String shpath= Thread.currentThread().getContextClassLoader().getResource("").getPath()+"config/logStatistic.sh"; Process ps =Runtime.getRuntime().exec(" chmod -R 777 " + shpath); ps.waitFor(); Process ps1 = Runtime.getRuntime().exec(" /bin/sh "+ shpath +" "+ScheduleConfig.getProperty("DAY")); ps1.waitFor(); BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } String result = sb.toString(); System.out.println(result); } catch (Exception e) { e.printStackTrace(); } }}
阅读全文
0 0
- 基于quartz-2.1.3.jar 的quartz调度表达式
- quartz调度器表达式
- Spring 任务调度Quartz的cron表达式
- 任务调度--Quartz的cron表达式
- 基于quartz任务调度组件的使用
- Quartz.NET--基于配置的调度方案
- 基于quartz的调度系统实现
- quartz任务调度Cron表达式
- spring 任务调度 Quartz 表达式
- Spring任务调度-基于Quartz
- quartz的作业调度
- JAR文件的Quartz
- quartz的作业调度触发Cron表达式说明
- quartz的作业调度触发Cron表达式说明
- Spring 调度工具Quartz cron 表达式的格式
- Spring 调度工具Quartz cron 表达式的格式
- MethodScheduler -- 基于Quartz的方法调度器 by java
- Quartz.net基于数据库的任务调度管理(Only.Jobs)
- ETH挖矿软件之挖矿专家
- 微软发行的SQL Server 2017候选版本可支持Linux
- Linux (CentOS)安装VNC+XFCE可视化桌面环境 附安装FireFox浏览器
- EDID 解析
- unity5.6.3发布Android
- 基于quartz-2.1.3.jar 的quartz调度表达式
- Linux 文件的解压和压缩 —— 文件类型
- CodeForces Gym101161D Find C
- 创建文件夹(文件)之 mkdir、mkdirs、createNewFile
- lsof命令详解
- PNG格式(中文)
- 在Maven项目中添加Oracle的驱动及配置POM文档
- C#中虚方法和抽象类的对比
- javascript实现日期按月份加减