1) java.util.Timer
This method is the most commonly used, but this method to manually start your tasks:
Timer timer = new Timer ();
Timer.schedule (new ListByDayTimerTask (), 10000,86400000);
ListByDayTimerTask here must extends TimerTask inside of the run () method.
2) ServletContextListener
This method containers in the web environment is relatively easy, so that the web server can be activated after
Automatic operation of the mandate, does not require manual operation.
ListByDayListener implements ServletContextListener interface will be in the
ContextInitialized start Timer way into the code, in contextDestroyed
Methods include cancel the Timer code and then in web.xml, by adding listener:
<Listener>
<Listener-class> com.qq.customer.ListByDayListener </ listener-class>
</ Listener>
3) org.springframework.scheduling.timer.ScheduledTimerTask
If you use a spring, then you do not need to write Timer category, in schedulingContext-timer
. Xml add the following text to be:
<? Xml version = "1.0" encoding = "UTF-8">
<! DOCTYPE beans PUBLIC "- / / SPRING / / DTD BEAN / / EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<Beans>
<Bean id = "timer" class = "org.springframework.scheduling.timer.TimerFactoryBean">
<Property name = "scheduledTimerTasks">
<List>
<Ref local = "MyTimeTask1" />
</ List>
</ Property>
</ Bean>
<Bean id = "MyTimeTask" class = "com.qq.timer.ListByDayTimerTask" />
<Bean id = "MyTimeTask1" class = "org.springframework.scheduling.timer.ScheduledTimerTask">
<Property name = "timerTask">
<Ref bean = "MyTimeTask" />
</ Property>
<Property name = "delay">
<Value> 10000 </ value>
</ Property>
<Property name = "period">
86400000 <value> </ value>
</ Property>
</ Bean>
</ Beans>
1) java.util.Timer
This method is the most commonly used, but this method to manually start your tasks:
Timer timer = new Timer ();
Timer.schedule (new ListByDayTimerTask (), 10000,86400000);
ListByDayTimerTask here must extends TimerTask inside of the run () method.
2) ServletContextListener
This method containers in the web environment is relatively easy, so that the web server can be activated after
Automatic operation of the mandate, does not require manual operation.
ListByDayListener implements ServletContextListener interface will be in the
ContextInitialized start Timer way into the code, in contextDestroyed
Methods include cancel the Timer code and then in web.xml, by adding listener:
<Listener>
<Listener-class> com.qq.customer.ListByDayListener </ listener-class>
</ Listener>
3) org.springframework.scheduling.timer.ScheduledTimerTask
If you use a spring, then you do not need to write Timer category, in schedulingContext-timer
. Xml add the following text to be:
<? Xml version = "1.0" encoding = "UTF-8">
<! DOCTYPE beans PUBLIC "- / / SPRING / / DTD BEAN / / EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<Beans>
<Bean id = "timer" class = "org.springframework.scheduling.timer.TimerFactoryBean">
<Property name = "scheduledTimerTasks">
<List>
<Ref local = "MyTimeTask1" />
</ List>
</ Property>
</ Bean>
<Bean id = "MyTimeTask" class = "com.qq.timer.ListByDayTimerTask" />
<Bean id = "MyTimeTask1" class = "org.springframework.scheduling.timer.ScheduledTimerTask">
<Property name = "timerTask">
<Ref bean = "MyTimeTask" />
</ Property>
<Property name = "delay">
<Value> 10000 </ value>
</ Property>
<Property name = "period">
86400000 <value> </ value>
</ Property>
</ Bean>
</ Beans> |