Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 488 Vote(s) - 3.46 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there a difference between ? and * in cron expressions? Strange example

#1
I have the following cron expression in my system:

0 0 0/1 1/1 * ? *

and you know what? I have no idea what it means. The guy who has written it is on his holiday for the next 2 weeks so I have to find out on myself. The documentation can be found [here][1]

According to the [documentation][1] we have:

* * * * * * *
| | | | | | |
| | | | | | +-- Year (range: 1970-2099)
| | | | | +---- Day of the Week (range: 1-7 or SUN-SAT)
| | | | +------ Month of the Year (range: 0-11 or JAN-DEC)
| | | +-------- Day of the Month (range: 1-31)
| | +---------- Hour (range: 0-23)
| +------------ Minute (range: 0-59)
+-------------- Second (range: 0-59)

Ok, let me tell you what I think: I believe that the expression means:

start when:
seconds: 0
minutes: 0
hours: 0
dayOfMonth 1
monthOfYear any
dayOfWeek any
year any

run every:
1 hour
1 dayOfWeek
when:
dayOfWeek same as on first execution

However available cron expression monitors says that it simply means every hour.
As the one who has written that is Senior Java Dev, he must have known any reason for writing such expression instead of:

0 0 * * * * *

We use `org.springframework.scheduling.quartz.QuartzJobBean`.

**Short summary**

Well, I think that my question is: what is the difference between `0 0 0/1 1/1 * ? *` and `0 0 * * * * *`?

**Edit:**

[The documentation][2] can be found here.



[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#2
There is no practical difference between <code>0 0 * * * ? *</code> and <code>0 0 0/1 1/1 * ? *</code>

Analyzing different marks:<br/>
<code>0/1</code> and <code>\*</code> for hours - first means start from hour 0 every day and repeat every hour, second one means: repeat every hour
<br/>
<code>1/1</code> and <code>\*</code> for days - fisrt means start from first day of the month and repeats every day and the second one means every day.

Reason why someone used complex expression maybe is that by testing, expression evaluated to this form and nobody undertook the job to simplify it or maybe previous cron version worked different.

Reply

#3
`0/1` means start at hour `0` and repeat each `1` hour<br>
`1/1` is start first day of the month and execute each `1` day

So this pattern **executes the cron once each hour, starting day one of month and repeating itself every day.**

>there is a requirement to use `?` in one of `dayOfWeek` or `dayOfMonth`: <br>
>Support for specifying both a day-of-week and a day-of-month value is not complete (you must currently use the ‘`?`’ character in one of these fields). – xenteros 7 mins ago

Then, `0 0 * * * ? *` (and not `0 0 * * * *`, with `?` mandatory as you commented) will be same expression, ignoring seconds and minutes and taking each value of other elements, will execute each hour and everyday.


----------

According your information:

0 0 0/1 1/1 * ? *
| | | | | | |
| | | | | | +-- Year (range: 1970-2099)
| | | | | +---- Day of the Week (range: 1-7 or SUN-SAT)
| | | | +------ Month of the Year (range: 0-11 or JAN-DEC)
| | | +--------- Day of the Month (range: 1-31)
| | +------------- Hour (range: 0-23)
| +---------------- Minute (range: 0-59)
+------------------ Second (range: 0-59)

And [this explanation][1] of the special characters:

**`*` (“all values”)**
>used to select all values within a field. For example, “” in the minute field means *“every minute”.

**`?` (“no specific value”)**
>useful when you need to specify something in one of the two fields in which the character is allowed, but not the other. For example, if I want my trigger to fire on a particular day of the month (say, the 10th), but don’t care what day of the week that happens to be, I would put “10” in the day-of-month field, and “?” in the day-of-week field.

**`/`**
>used to specify increments. For example, “0/15” in the seconds field means “the seconds 0, 15, 30, and 45”. And “5/15” in the seconds field means “the seconds 5, 20, 35, and 50”. You can also specify ‘/’ after the ‘’ character - in this case ‘’ is equivalent to having ‘0’ before the ‘/’. ‘1/3’ in the day-of-month field means “fire every 3 days starting on the first day of the month”.

----------

# differences between `*` and `?`

To explain difference between `?` and `*` in the expressions, first of all take a look at this table:

Field Name Mandatory Allowed Values Allowed Special Characters
Seconds YES 0-59 , - * /
Minutes YES 0-59 , - * /
Hours YES 0-23 , - * /
Day of month YES 1-31 , - * ? / L W //allowed '?'
Month YES 1-12 or JAN-DEC , - * /
Day of week YES 1-7 or SUN-SAT , - * ? / L # //allowed '?'
Year NO empty, 1970-2099 , - * /

As you can see `?` is only allowed in `Day of month` and `Day of week` is mandatory in one of both fields and will tell Quartz this value has not been defined, thus, use the other field (if you put `?` into `Day of month`, the value used will be `Day of week`).


[1]:

[To see links please register here]

Reply

#4
Not an answer, just an update to the correct answer of @joc.

As for now, [QuartzScheduler specifically][1] points it out that `?` could be applied in one of the two positions: `day_of_month` or `day_of_week`.

> Support for specifying both a day-of-week and a day-of-month value is not complete (you must currently use the ‘?’ character in one of these fields).

Besides in the link enclosed above, there are lots of examples to guide you well enough to come up with your own.

```

+--------------------+-------------------------------------------------------------------------------------------------------------------------------------+
| **Expression** | **Meaning** |
+--------------------+-------------------------------------------------------------------------------------------------------------------------------------+
| 0 0 12 * * ? | Fire at 12pm (noon) every day |
| 0 15 10 ? * * | Fire at 10:15am every day |
| 0 15 10 * * ? | Fire at 10:15am every day |
| 0 15 10 * * ? * | Fire at 10:15am every day |
| 0 15 10 * * ? 2005 | Fire at 10:15am every day during the year 2005 |
| 0 * 14 * * ? | Fire every minute starting at 2pm and ending at 2:59pm, every day |
| 0 0/5 14 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, every day |
| 0 0/5 14,18 * * ? | Fire every 5 minutes starting at 2pm and ending at 2:55pm, AND fire every 5 minutes starting at 6pm and ending at 6:55pm, every day |
+--------------------+-------------------------------------------------------------------------------------------------------------------------------------+

```

[1]:

[To see links please register here]

Reply

#5
You can use this website as a quick way to generate and understand cron expressions syntax without much knowledge about the cron format syntax:

[To see links please register here]


The website uses Quartz cron format. For example, your expression means the next scheduled dates are in every hour:
[![enter image description here][1]][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through