Difference between * and ? in Spring @Scheduled(cron=".....")
The tutorial is outdated. The symbol ?
means exactly the same than *
. As of Spring 3.1.2.RELEASE, the call hierarchy is:
The constructor CronTrigger(String)
calls the constructor CronSequenceGenerator(String)
which calls parse(String)
which calls setDays(BitSet bits, String field, int max)
. Its implementation is clear:
private void setDays(BitSet bits, String field, int max) {
if (field.contains("?")) {
field = "*";
}
setNumberHits(bits, field, 0, max);
}
So, if ?
, then *
.
asterix stands for all possible values. question marks should be used for non specific value
*("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. See the examples below for clarification.
Copied from the tutorial