Cron Expression: What's the Difference? and * in cron expression?

It seems to me that both mean "any of the available values." What exactly is the difference between the two?

+5
source share
3 answers

* means all possible values ​​in the field. ? means you don't care about meaning. It is used when you have two fields that may conflict with each other. A common example is the fields of the month of the month and the day of the week. Consider, for example, the cron specification for working at 10am on the first day of each month:

 0 0 10 1 * ? * 

Now undo it:

  • Seconds: 0 - we want it to work at 10:00: 00
  • Minutes: 0 - we want it to work at 10: 00 : 00
  • Hours: 10 - we want it to work at 10 : 00: 00
  • Day of the month: 1 - we want it to start on the 1st of every month.
  • Month: * - we want it to run every month (for example, January 1, February 1, etc.).
  • Day of the week ? - we don’t care about the day of the week. Cron should work on the 1st of every month, regardless of whether it is Sunday, Monday, etc.
  • Year: * - we want it to run every year
+5
source

From Quartz Scheduler

* ("all values") - used to select all values ​​in the field. For example, “*” in the minute field means “every minute”.

? ("no specific meaning") - useful when you need to specify something in one of two fields in which the character is allowed, but not Others. For example, if I want my trigger to fire on a specific day of the month (say, the 10th), but no matter what day of the week, what happens, I would put "10" in the "day of the month" and "?" on the day of the week. See the examples below for clarification.

+1
source

The * character is used to indicate all values. For example, “ * ” in the minutes field means “every minute”.

Symbol ? allowed for the fields of the day of the month and day of the week. It is used to indicate "no special meaning." This is useful when you need to specify something in one of two fields, but not in the other. See the examples below for clarification.

You can see more here: http://docs.netkernel.org/book/view/book:mod:cron/doc:mod:cron:cronexpression

Also, if you need to create a Cron expression, you can use this: http://www.cronmaker.com/

0
source

Source: https://habr.com/ru/post/1237908/


All Articles