Spring4 multiple timer details, spring4 timer details
Note: spring4 does not have the org. springframework. scheduling. timer. ScheduledTimerTask class, so the timerTask method before spring3 cannot be used. Two methods are recommended for the spring4 timer method: (you need to import the quartz package separately, only 1.8. +)
The spring code is as follows:
<Span style = "white-space: pre"> </span> <! -- Method 1 --> <bean name = "exampleJob" class = "org. springframework. scheduling. quartz. jobDetailBean "> <property name =" jobClass "value =" com. spring. task. taskOne "/> <property name =" jobDataAsMap "> <map> <entry key =" timeout "value =" 5 "/> </map> </property> </bean> <bean id = "cronTrigger" class = "org. springframework. scheduling. quartz. cronTriggerFactoryBean "> <property name =" jobDetail "ref =" exampleJob "/> <! -- Run every morning at 6 AM --> <! -- <Property name = "cronExpression" value = "0 0 6 **? "/> --> <! -- <Property name = "cronExpression" value = "0 0/1 ***? "/> --> <! -- Per minute --> <property name = "cronExpression" value = "0/2 ****? "/> <! -- Per second --> </bean> <! -- Method 2 --> <bean id = "exampleBusinessObject" class = "com. spring. task. taskTwo "/> <bean id =" jobDetail "class =" org. springframework. scheduling. quartz. methodInvokingJobDetailFactoryBean "> <property name =" targetObject "ref =" exampleBusinessObject "/> <property name =" targetMethod "value =" doIt "/> <property name =" concurrent "value = "false"/> </bean> <bean id = "simpleTrigger" class = "org. springframework. scheduling. quart Z. SimpleTriggerFactoryBean "> <! -- See the example of method invoking job above --> <property name = "jobDetail" ref = "jobDetail"/> <! -- 10 seconds --> <property name = "startDelay" value = "5000"/> <! -- Repeat every 50 seconds --> <property name = "repeatInterval" value = "3000"/> </bean> <! -- The general scheduling is used to start the Spring timer --> <bean class = "org. springframework. scheduling. quartz. schedulerFactoryBean "> <property name =" triggers "> <list> <ref bean =" cronTrigger "/> <ref bean =" simpleTrigger "/> </list> </property> </bean>
The JAVA code is as follows (method 1 ):
Package com. spring. task; import org. apache. log4j. logger; import org. quartz. jobExecutionContext; import org. quartz. jobExecutionException; import org. springframework. scheduling. quartz. quartzJobBean; public class TaskOne extends QuartzJobBean {protected static final Logger log = Logger. getLogger (TaskOne. class); private int timeout;/*** Setter called after the ExampleJob is instantiated * with the value from the JobDetailBean (5) */public void setTimeout (int timeout) {this. timeout = timeout;} @ Overrideprotected void executeInternal (JobExecutionContext arg0) throws JobExecutionException {// TODO Auto-generated method stublog.info ("----- scheduled task execution -----");}}
The JAVA code is as follows (
2
):
Package com. spring. task; import org. apache. log4j. logger; public class TaskTwo {protected static final Logger log = Logger. getLogger (TaskTwo. class); public void doIt () {log.info ("----- scheduled task execution -----");}}