首先创建一个定时器类:
@Component("cacheTimer")
public class CacheTimer extends TimerTask {
public static boolean isRun = false;
@Override
public void run() {
// TODO Auto-generated method stub
if(!isRun){
isRun = true;
System.out.println("this is run!");
isRun = false;
}
}
}
然后配置applicationContext.xml文件
<bean id="cacheExecutor" class="org.springframework.scheduling.concurrent.ScheduledExecutorTask">
<property name="runnable" ref="cacheTimer" />
<property name="delay" value="0" />
<property name="period" value="3600000" />
</bean>
<bean class="org.springframework.scheduling.concurrent.ScheduledExecutorFactoryBean">
<property name="poolSize" value="1" />
<property name="scheduledExecutorTasks">
<list>
<ref bean="cacheExecutor"/>
</list>
</property>
</bean>
这样就完成了一个定时器的配置