首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

quartz 如何立即执行

2013-04-27 
quartz 怎么立即执行现在 有3个定时任务 1 每个月6号执行2 周1删除某些数据3 周五修改到时间执行倒是没问

quartz 怎么立即执行
现在 有3个定时任务 
1 每个月6号执行
2 周1删除某些数据
3 周五修改

到时间执行倒是没问题,但是如果服务器在执行的前一秒挂了 在重启服务器后时间过了
这个应该怎么处理?

配置文件:
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
        <!-- 要调用的工作类 -->
    <!-- 每月6号执行 -->
        <bean id="Job1" class="cn.jq.rb.Dao.impl.QuertzImpl"></bean>
       
        <!-- job 1                 start            -->
        <bean id="jobtask1" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <!-- 调用的类 -->
            <property name="targetObject">
             <ref bean="Job1"/>
            </property>
            <!-- 调用类中的方法 -->
            <property name="targetMethod">
                <value>work1</value>
            </property>
        </bean>
        <!-- 定义触发时间 -->
        <bean id="doTime1" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask1"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
                <!--间隔-->
                <value>0 0 0 6 * ?</value>
            </property>
        </bean>
     
        <!-- job 2                 start            -->


        <!-- 周五凌晨执行 -->
         <!-- 定义调用对象和调用对象的方法 -->
        <bean id="jobtask2" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <!-- 调用的类 -->
            <property name="targetObject">
             <ref bean="Job1"/>
            </property>
            <!-- 调用类中的方法 -->
            <property name="targetMethod">
                <value>work2</value>
            </property>
        </bean>
        <!-- 定义触发时间 -->
        <bean id="doTime2" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask2"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
                <!-- 间隔-->
                <value>0 0 0 ? * 6</value>
            </property>
        </bean>
        
        <!-- job 3                 start            -->
        <!--  周1删除数据 -->
         <!-- 定义调用对象和调用对象的方法 -->
        <bean id="jobtask3" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <!-- 调用的类 -->
            <property name="targetObject">
             <ref bean="Job1"/>
            </property>
            <!-- 调用类中的方法 -->
            <property name="targetMethod">
                <value>work3</value>
            </property>


        </bean>
        <!-- 定义触发时间 -->
        <bean id="doTime3" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail">
                <ref bean="jobtask3"/>
            </property>
            <!-- cron表达式 -->
            <property name="cronExpression">
                <!-- 间隔-->
                <value>0 0 0 ? * 2</value>
            </property>
        </bean>
        <!--           end            -->
        
        <!-- 总管理类 如果将lazy-init='false'那么容器启动就会执行调度程序 -->
        <bean id="startQuertz" lazy-init="false" autowire="no" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
            <property name="triggers">
                <list>
                    <ref bean="doTime1"/>
                    <ref bean="doTime2"/>
                    <ref bean="doTime3"/>
                </list>
            </property>
        </bean>
   
</beans>


[解决办法]
你这种情况好像只会在下一个周期里面再执行了。
但是你可以通过程序手工执行一次啊。
[解决办法]
http://blog.csdn.net/sunxiangfei91/article/details/8773664    去看看这个。。希望有帮助

热点排行