50

now I have this configuration my my scheduler:

<task:scheduled ref="task" method="run" cron="0 45 22 * * *" />

when this task is executed ? and how I can change it to do this task every minute

nurettin
  • 11,090
  • 5
  • 65
  • 85
hudi
  • 15,555
  • 47
  • 142
  • 246

2 Answers2

108

This task is executed at 22:45:00 every day, every week, every month.

To execute a task every minute, use

0 * * * * *
8

The accepted answer is correct for spring. Other than that, one should be careful whether the target system uses 6 or 5-digits cron.

With 5-digits-crons

0 * * * * schedules to be run "at minute 0" (hence every hour).

The correct answer in this case should be either

* * * * *

or

*/1 * * * *

Also see: Spring cron vs normal cron?

nicost
  • 1,022
  • 2
  • 11
  • 27
  • 6
    0 * * * * * is at second 0. You missed one star. – mchern1kov May 22 '18 at 07:34
  • Actually, it depends.. :-) Officially cron has 5 digits, whereas some cron implementations (4th BSD edition on Linux or the nncron deamon for Windows) support a sixth digit. (Ref: https://en.wikipedia.org/wiki/Cron) – nicost May 22 '18 at 09:27
  • 18
    I know it, but i'm talking about Spring. It uses 6 digits cron. – mchern1kov May 24 '18 at 09:26
  • This answer is wrong. I updated the question's tags. – nurettin Oct 15 '18 at 12:31
  • This gives error Caused by: java.lang.IllegalStateException: Encountered invalid @Scheduled method 'schedule': Cron expression must consist of 6 fields (found 5 in "*/1 * * * *") – Manas Saxena Feb 10 '22 at 13:43
  • As mentioned, for spring cron expressions do not ofollow the UNIX cron expressions, thus you should use 6 digits when using spring: https://stackoverflow.com/questions/30887822/spring-cron-vs-normal-cron – nicost Apr 01 '22 at 06:59