Spring task provides two ways to configure, as you can imagine, or one is annotation (callout), and the other is XML configuration. But in fact, I feel more awkward here, because the task of scheduling such requirements, usually changes are more, if you use annotation way, the change becomes troublesome, must go to recompile. So, I just chose to configure it in XML, but I still habitually enable labeling, just like the AOP configuration. Annotation method Please find your own @scheduled
The specific configuration can be referenced as follows
XML code
- <? XML version= "1.0" encoding="UTF-8"?>
- <beans xmlns="Http://www.springframework.org/schema/beans"
- xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http// Www.springframework.org/schema/task "
- xsi:schemalocation= "
- Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
- Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd ">
- <Bean id= "reminderprocessor" class="Com.foo.task.ReminderProcessor">
- <property name="Workers">
- <array value-type="Com.foo.task.Worker">
- <ref bean="Projectscheduleremindworker" />
- </Array>
- </Property>
- </Bean>
- <!--Configure Task Linear pool --
- <task:executor id="executor" pool-size="3" />
- <task:scheduler id="Scheduler" pool-size="3" />
- <!--enable annotation mode --
- <task:annotation-driven scheduler="Scheduler"
- executor="executor" proxy-target-class="true" />
- <task:scheduled-tasks scheduler="Scheduler">
- <task:scheduled ref="reminderprocessor" method="process"
- cron="0 0 12 * *?" />
- </task:scheduled-tasks>
- </Beans>
See the core section
XML code
- <task:scheduled-tasks scheduler="Scheduler">
- <task:scheduled ref="reminderprocessor" method="process"
- cron="0 0 12 * *?" />
- </task:scheduled-tasks>
This means that the process method in the bean is executed at 12 o ' Reminderprocessor per day. Cron configuration expressions are basically consistent with quartz, but the actual measurements do not support some special characters, such as L,w and z when configuring days, because of the need to perform task scheduling on the third day of the month, but I configure the springtask to report illegal characters.
Therefore, the gap between quartz and springtask is also obvious. Springtask is very simple to use, after all, spring's own, although with quartz can also achieve a combination, but not so simple. and Springtask function is not quartz powerful, quartz cluster and advanced features to go. So you can choose for yourself. But in general, think springtask enough.
Attach a detailed UML description of my example
Use of Task Task Scheduler for spring