Take the previous article (simple example of the basic operation of the spring timed task):
Ii. Spring timed tasks: Multiple tasks and execution interval configuration
1, the use of multiple tasks:
The first step: Write the class and method of performing timed task (multiple, refer to previous article)
Step Two: Config
1.Integration of timed tasks in spring bootIn the Startup class, add an annotation that opens a timed task:The use of timed tasks in Springboot is fairly straightforward. First, we add @enablescheduling to the startup class to open the timed task.@EnableScheduling Public class startapplication { publicstaticvoid main (string[] args) { Springapplication.run (startapplication. class ,
(initialdelay=1000, fixedrate=5000): Executes after the first delay of 1 seconds, followed by fixedrate rules every 5 seconds
@Scheduled (cron= "/5"): Define rules by cron expressions, what are CRO expressions, self-search engines.
TestStart the Springboot project, the console has not been 5s to print out the current time.
2017-04-29 17:39:37.672 INFO 677-[pool-1-thread-1] com.forezp.task.ScheduledTasks:The time is now 17:39:372017-04-29 17:39:42.671 INFO 677-[pool-1-thread-1]
This article describes job visualizations (management, imperfect visual management of this article) when using the job framework of spring (spring inherited and simplified quartz)The solution is to use listeners to implement job history, job statistics, exception logging, manual trigger JobLet's take a look at the implementation processHere you only need to implement several listeners and register to-Statis
In a recent spring MVC project, you need to perform a task regularly, so you use spring's own task functionality. When debugging locally, everything is fine, but once deployed to the server, each task is called two times. After searching for related problems on the Internet, excluding the problem of repeating annotatio
This article address: http://blog.csdn.net/kongxx/article/details/6751300
The integration of task scheduling in spring, in addition to using the JDK timer and TimerTask classes to implement simple task scheduling, can be implemented using the enterprise-class open source job scheduling framework Quartz, below is a small example:
1. The first is a
Environment: Myeclipse10.7+spring 3.1First, write the task class on the server sidePackage Com.conbao.component.task.controller;import Java.text.dateformat;import Java.text.simpledateformat;import Java.util.date;import Org.springframework.scheduling.annotation.scheduled;import org.springframework.stereotype.component;/** * Timed Task Job Class * * @author Code C
padding can be set to height, etc.2.div Horizontal Vertical centering problemSet absolute positioning, left, top each accounted for 50%,margin-left-(WIDTH/2); Margin-top is-(HEIGHT/2)3.div Corner arc problemRelative to the parent element for absolute positioning, set the relative values of height, width, and Border-radius (the same value, forming a rounded arc), the other to set top, left, right, bottom value, according to the corner of the different locations to set, such aswidth:50px;height:5
Java implements timed tasks typically using a timer, or using the quartz component. Now the spring boot provides a more convenient way to implement it.Spring boot has integrated the scheduled tasks. Use @secheduled annotations.@Component//Enable Scheduled Tasks@EnableScheduling Public classTagpushscheduler {Private StaticLogger log = Logger.getlogger (Tagpushscheduler.class); @Scheduled (cron = "0/10 * * * * *?") //executes once every 10 seconds P
schedule on the 20th of each month, regardless of whether the 20th is the day of the week, you can only use the following: 0 0 0 20 *?, the last one can only be used? , but not with *, if using * means that the day of the week will trigger, in fact it is not.The "C" character: Available for the day and week fields, which is the abbreviation for "Calendar". It represents the value, if any, that is computed based on the associated calendar. If there is no associated calendar, it is equivalent to
continuous interval (9-12), a time interval (8-18/4) (/= every 4 hours), a list (1,3,5), and a wildcard character. * Because the "date in month" and "Day of the Week" are mutually exclusive, one of the two elements must be set?. */@Scheduled (Cron= "5 * * * *?") Public voidcronscheduled () {Log.info ("Cron:the time is now {}", Dateformat.format (NewDate ())); }}Enable Scheduled Tasks PackageCom.zooper.demo;Importorg.springframework.boot.SpringApplication;Importorg.springframework.boot.a
1. First add a comment on the startup initiator @EnableScheduling2. Add a comment on the task method to be timed @Scheduled (fixedrate = 20000) output at the console every 20 secondsA cron expression has at least 6 (or possibly 7) time elements that have a space separation.In order ofSeconds (0~59)Minutes (0~59)Hours (0~23)Days (months) (0~31, but you need to consider the number of days of your month)Month (0~11)Days (weeks) (1~7 1=sun or Sun,mon,tue,
When you use Spring Timed Task Pack quartz, you must use the following versions of Quartz1.85. View found spring3.0.5 in Org.springframework.scheduling.quartz.CronTriggerBean inheritedOrg.quartz.CronTrigger (public class Crontriggerbeanextends Crontrigger),in quartz2.1.3 Org.quartz.CronTrigger is an interface (Publicabstract interface Crontrigger extends Trigger),in quartz1.8.5 and 1.8.4 Org.quartz.CronTrig
In spring MVC, the container is loaded automatically when the project is started, but at ordinary times it needs to be done at the start of the project, which is used in the container, and can be accomplished by implementing the Applicationlistener interface.
A class that implements the Applicationlistener interface that is notified whenever a applicationevent is published to the ApplicationContext (that is, the context, also known as a container), Ne
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.