Timing task || Cron Expressions

Spring built-in Spring Task, which is Spring3.0 join the scheduled tasks function.

Annotation mode timer start using data crawling reptiles.

We are using @Scheduled notes , its properties as follows:

1) cron: cron expression that specifies the task execution at a specific time ;

2) FIXEDDELAY : The last time how long after the task execution and then executed , with parameters of type long, in ms

3) fixedDelayString: Like fixedDelay meaning, just type parameters become String

. 4) fixedRate: according to a certain frequency of tasks, the parameter type as long, in ms

5) fixedRateString: Like the meaning fixedRate, but the parameter type to String

6) initialDelay: delayed again for the first time how long the mission, parameters of type long, in ms

7) initialDelayString : Like the meaning initialDelay, but the parameter type to String

8) Zone: time zone defaults to the current time zone, generally do not use

Use here is relatively simple, fixed interval of time to start crawling . For example, can be achieved after the project started, one hour every start a reptile.

But more likely the business requirements, the timing is not regularly deal with, but are processed at a specific time, this time before use can not meet demand. For example, to execute on weekdays (Monday to Friday) night eight. Then we need to Cron expressions.



Cron Expressions

cron expression is a string , is actually made up of seven sub-expression, describing the details of the individual timetable. These separate sub-expressions are blank , representing:

1.  Seconds

2.  Minutes

3.  Hours

4.  Day-of-Month

5.  Month

6.  Day-of-Week

7. Year (optional field)


Cases "0 0 12? * WED" at 12:00 every Wednesday afternoon execution,

 "*" Is representative of the time period


Each field has a valid value can be specified, such as

Seconds The (sec): 0-59 can be numerically expressed,

Minutes (min): may be represented by numbers 0-59,

Hours (time): 0-23 can be numerically expressed,

Day-of-Month (days): may be any number by a value of 1 to 31, but some special attention Month

Month (March): 0-11 can be used with or string:

JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC

Day-of-Week (days): 1-7 can be numerically represented (1 = Sunday) or a character string port:

Sun, Mon, Tue, Wed, Thu, Fri, SAT


"/": Special unit is expressed as "per" such as "0/15" indicates executed once every 15 minutes, "0" indicates the start from "0" points, "3/20" indicates represents every 20 minutes once, "3" represents the beginning of the 3rd minute

"?": That one day a month, one day or the first week of

"L": for a month, or every week, last week expressed as the last day of each month, or every month a few such "6L" means "the last Friday of each month."


Published 434 original articles · won praise 105 · views 70000 +

Guess you like

Origin blog.csdn.net/qq_39368007/article/details/105054201