2011-07-26 59 views
0

嗨我是Spring框架本身的新手,我正在實現Spring調度框架。我寫了我的類和方法來執行。Spring調度框架

現在我所做的只是添加下面的代碼,spring.xml

 <bean id="schedulerInstance" class="com.package.SchedulerService"> 
    <property name="maxAgeTableOne" value="30"/> 
    <property name="maxAgeTableTwo" value="30"/> 
    <property name="maxAgeTableThree" value="30"/> 
</bean> 


    <task:scheduled-tasks scheduler="taskScheduler"> 
    <!-- An interval-based trigger where the interval is measured from the completion time of the previous task. --> 
    <task:scheduled ref="schedulerInstance" method="cleanuptableone" cron="0 0 23 1 * ? " /> 
    <task:scheduled ref="schedulerInstance" method="cleanuptabletwo" cron="0 0 23 1 * ? "/> 
    <task:scheduled ref="schedulerInstance" method="cleanuptablethree" cron="0 0 23 1 * ? " /> 

</task:scheduled-tasks> 

<!-- Defines a ThreadPoolTaskScheduler instance with configurable pool size. --> 
<task:scheduler id="taskScheduler" pool-size="1"/> 

從我認爲它現在計劃每月運行,但它似乎沒有工作或運行的任何事情?有什麼我應該做的嗎?

上面的SchedulerService類是純java類,沒有任何彈簧相關或調度相關的東西。

請指導我還應該做些什麼來使課程成爲預定課程。

感謝, SS

回答

1

我不知道這是必然的答案,但我比你的實現是一個工作落實,我有:

<task:scheduler id="scheduler_project" 
    pool-size="1" /> 
<task:scheduled-tasks scheduler="scheduler_project"> 
    <task:scheduled ref="execObj" method="start" cron="0 0-59 * * * *" /> 
</task:scheduled-tasks> 

似乎有沒有多大除「?」以外的區別在cron時間表中。

我可能建議你減少測試用例,在更頻繁的迭代上運行一個簡單的命令,以確保沒有代碼問題發揮作用?可能揭露潛在問題的地方。

+0

因此,即使我改變了每分鐘運行的cron作業的頻率,我在日誌中沒有看到任何內容,但我還是有全部的日誌語句。我是否應該使用@Scheduled之類的任何註釋,以便春天知道特定計劃會運行?謝謝。 –

+0

單元測試(Junit)運行正常,出現問題。 –

+0

你是如何運行這個代碼的,從主或部署到tomcat或同等的?如果來自主,什麼代碼加載春天上下文?如果來自tomcat,您是否使用ContextLoadListener進行初始化? – cmutt78