Spring定时器

来源:互联网 发布:淘宝人参怎么这么便宜 编辑:程序博客网 时间:2024/06/01 10:28
<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <!-- 需要spring-support.jar包 -->
    
    <bean id="job" class="com.njg.spider.job.BaseJob">
         <property name="taskDao" ref="taskDao" ></property>
    </bean>

    <bean id="quartzClock" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="job"/>
        <property name="targetMethod" value="start"/>
        <property name="concurrent" value="false"/>
    </bean>
    
    <bean id="spider" class="org.springframework.scheduling.quartz.CronTriggerBean">
        <property name="jobDetail" ref="quartzClock"></property>
        <property name="cronExpression">
            <!-- 每天上午8点,12点,下午4点执行定时器 定时更新当天的信息 -->
            <value>0 0 8,12,16 * * ?</value>
             <!-- 一个cron表达式有至少6个(也可能是7个)由空格分隔的时间元素.从左到右,这些元素的定义如下:  
                   1.秒(0-59)  
                   2.分钟(0-59)  
                   3.小时(0-23)  
                   4.月份中的日期(1-31)  
                   5.月份(1-12或SUN-DEC)  
                   6.星期中的日期(1-7或SUN-SAT)  
                   7.年份(1970-2099)   
                  例子:  
                   0 0 10,14,16 * * ? 每天上午10点,下午2点和下午4点  
                   0 0,15,30,45 * 1-10 * ? 每月前10天每隔15分钟  
                   30 0 0 1 1 ? 2012 在2012年1月1日午夜过30秒时  
                   0 0 8-5 ? * MON-FRI 每个工作日的工作时间  
                    
                   - 区间  
                   * 通配符  
                   ? 你不想设置那个字段  
                  -->  
        </property>
    </bean>
    
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">  
        <property name="triggers">  
            <list>
                <ref bean="spider"></ref>
            </list>  
        </property>  
    </bean>
    
</beans>
原创粉丝点击