Use of Task Task Scheduler for spring

Source: Internet
Author: User

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
  1. <? XML version= "1.0" encoding="UTF-8"?>
  2. <beans xmlns="Http://www.springframework.org/schema/beans"
  3. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:task="http// Www.springframework.org/schema/task "
  4. xsi:schemalocation= "
  5. Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  6. Http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd ">
  7. <Bean id= "reminderprocessor" class="Com.foo.task.ReminderProcessor">
  8. <property name="Workers">
  9. <array value-type="Com.foo.task.Worker">
  10. <ref bean="Projectscheduleremindworker" />
  11. </Array>
  12. </Property>
  13. </Bean>
  14. <!--Configure Task Linear pool --
  15. <task:executor id="executor" pool-size="3" />
  16. <task:scheduler id="Scheduler" pool-size="3" />
  17. <!--enable annotation mode --
  18. <task:annotation-driven scheduler="Scheduler"
  19. executor="executor" proxy-target-class="true" />
  20. <task:scheduled-tasks scheduler="Scheduler">
  21. <task:scheduled ref="reminderprocessor" method="process"
  22. cron="0 0 12 * *?" />
  23. </task:scheduled-tasks>
  24. </Beans>

See the core section

XML code
    1. <task:scheduled-tasks scheduler="Scheduler">
    2. <task:scheduled ref="reminderprocessor" method="process"
    3. cron="0 0 12 * *?" />
    4. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.