1,三种方式: quartz,Timer,Executor 详情参考 : http://blog.csdn.net/52rainbow/article/details/4004206
2,具体例子:
http://www.blogjava.net/sundc/archive/2007/10/19/154355.html
http://beyondlovew.iteye.com/blog/436973
3,还有一点要说明,quartz可以实现动态设置Cron表达式,也可以设置手工触发方式来控制scheduler.
注意下面划线部分,想要手工控制scheduler,可以先获取SchedulerFactoryBean,通过它,可以控制调度,还可以取得CronTriggerBean,进而动态设置cronExpression。
<bean id="push2UcScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
<property name="triggers">
<list>
<ref local="push2UcTrigger"/>
</list>
</property>
<property name="autoStartup" value="false" />
<property name="schedulerName" value="push2UcScheduler" />
</bean>
<bean id="push2UcTrigger" class="org.springframework.scheduling.quartz.CronTriggerBean">
<property name="jobDetail">
<ref bean="push2UcJob"/>
</property> <property name="cronExpression">
<!--每1分钟向UC推送一次 -->
<value>0 0/1 * * * ?</value>
</property> </bean>
<bean id="push2UcJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
<property name="targetObject">
<ref bean="ucManagerAO"/>
</property>
<property name="targetMethod">
<value>addItemToUc</value>
</property>
<property name="concurrent" value="false" />
</bean>
来源:oschina
链接:https://my.oschina.net/u/162836/blog/28153