基于quartz-2.1.3.jar 的quartz调度表达式

下载 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>
  1. quartz 配置文件 quartz.properties
org.quartz.scheduler.instanceName: DefaultQuartzScheduler
org.quartz.scheduler.rmi.export: false
org.quartz.scheduler.rmi.proxy: false
org.quartz.scheduler.wrapJobExecutionInUserTransaction: false

org.quartz.threadPool.class: org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount: 1
org.quartz.threadPool.threadPriority: 5
org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread: true

org.quartz.jobStore.misfireThreshold: 60000

org.quartz.jobStore.class: org.quartz.simpl.RAMJobStore
  1. 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
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

科学的N次方

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值