1.TimerTask
>>配置文件default-lazy-init="false"如果为true则不会启动Timer
>>INFO [org.springframework.scheduling.timer.TimerFactoryBean] - Initializing Timer
表示启动了定时.
>>但是用AbstractDependencyInjectionSpringContextTests这个类来加载spring的配置文件后虽然启动了定时任务,但是马上执行以下步骤:
Closing application context
Destroying singletons in...
Cancelling Timer
所以定时任务不能执行.
>>如果使用new ClassPathXmlApplicationContext(String[])来加载配置文件,则在Initializing Timer后就程序就退出了,真是怪事.
>>用org.springframework.web.context.ContextLoaderListener 在web应用环境下加载配置文件可以正确执行定时任务.
spring bean配置如下:
1.<bean id="scheduledTask" class="org.springframework.scheduling.timer.ScheduledTimerTask">
2. <property name="delay" value="1000" />
3. <property name="period" value="50000" />
4. <property name="timerTask" ref="scoringService" />
5.</bean>
6.<bean id="timerFactory" class="org.springframework.scheduling.timer.TimerFactoryBean">
7. <property name="scheduledTimerTasks">
8. <list>
9. <ref bean="scheduledTask" />
10. </list>
11. </property>
12. <property name="daemon" value="true"/>
13.</bean>
2.quartz
>>使用autowire by name的禁忌:不要有叫dataSource的bean存在.
见http://eyejava.iteye.com/blog/58281
>>cronExpression和unix cronTab文件的区别
cronTab没有秒 和 年这两个栏位,cronTab 的星期天用0表示,cronExpression用7表示