我想讀取CVS文件並將其每24小時插入到數據庫中。我使用Spring Schedular並按預期工作,但我的應用程序將部署在3個不同的JVM和所有JVM將同時運行,那麼對於所有三個JVM,schedular將只運行一次,因此它每天只能插入一次數據。Spring Scheduler每24小時
<bean id="runMeTask"
class="com.fifththird.ebusiness.ivr.core.service.RunMeTask" >
<property name="dataSource" ref="DataSource"/>
</bean>
<bean id="schedulerTask"
class="org.springframework.scheduling.timer.MethodInvokingTimerTaskFactoryBean">
<property name="targetObject" ref="runMeTask" />
<property name="targetMethod" value="printMe" />
</bean>
<bean id="timerTask"
class="org.springframework.scheduling.timer.ScheduledTimerTask">
<property name="timerTask" ref="schedulerTask" />
<property name="delay" value="1000" />
<property name="period" value="60000" />
</bean>
<bean class="org.springframework.scheduling.timer.TimerFactoryBean">
<property name="scheduledTimerTasks">
<list>
<ref local="timerTask" />
</list>
</property>
</bean>
添加到上面的問題:「如果部署在三個不同的JVM相同apllication將撥打電話去春來程序器,那麼代碼將嘗試三次/日來插入數據。」
Thnx爲您的答案,但如果兩個JVM同時呼叫鎖定,該怎麼辦? – user970500
兩個JVM不能同時獲得文件上的鎖定 –