代码之家  ›  专栏  ›  技术社区  ›  black sensei

春季的quarz-cron任务究竟是由什么来执行的?

  •  1
  • black sensei  · 技术社区  · 16 年前

    <!--Scheduling-->
    <!--Job-->
        <bean id="projUpdater" class="org.springframework.scheduling.quartz.JobDetailBean">
            <property name="jobClass" value="com.myproject.utilscheduling.quartz.ProjUpdaterCronImpl" />
        </bean>
    <!---End of Jobs-->
    <!--Triggers-->
        <bean id="regularUpdateTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
            <property name="jobDetail" ref="projUpdater"/>
            <property name="cronExpression" value="30 1 * * * ?"/>
        </bean>
    <!--End ofTriggers-->
    <!--Scheduler Factory-->
    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="regularUpdateTrigger"/>
            </list>
        </property>
    </bean>
    <!--End of Scheduler Factory-->
    <!--End of Scheduling-->
    

    public class ProjUpdaterCronImpl extends QuartzJobBean {
    
    public ProjUpdaterCronImpl() {
    }
    
    
    protected void executeInternal (JobExecutionContext ctx) throws JobExecutionException {
        System.out.println("[JOB] " + new Date() + "hello");
    }
    
    }
    

    public class NewMain {
    
    /**
     * @param args the command line arguments
     */
     public static void main(String[] args) {
        System.out.println("starting job");
     }
    
    }
    

    因此,据我所知,该作业将在1mn30s后开始,并发布在控制台上。我错了。我遇到了几个或多个我解决的错误,所以我可以安全地假设spring配置文件中没有错误,因为在构建和运行时没有错误。那么,我做错了什么,或者我忘了做什么?

    2 回复  |  直到 16 年前
        1
  •  1
  •   Chin Huang    16 年前

    <property name="cronExpression" value="30 1 * * * ?"/>
    

    实际上将触发器配置为每小时在1分30秒后触发一次。

    MethodInvokingJobDetailFactoryBean

        2
  •  0
  •   Zoidberg    16 年前

    <bean id="projUpdater" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
            <property name="targetObject" ref="registeredObject" />
            <property name="targetMethod" value="methodNameInObject" />
        </bean>