i have spring boot project with a cron job. the job should be run only once. it should trigger again only if app is crashed or app is restarted. is there any cron expression for this ? or any way to achieve this ?
Asked
Active
Viewed 2,516 times
3
-
2Cron is a time based scheduler. It's the wrong tool for jobs that only need to run once. – 1615903 Dec 31 '20 at 09:57
-
2you should not use a cron expression for this, just use the logic to run whenever the app starts. – luk2302 Dec 31 '20 at 09:57
1 Answers
5
If run once when app start, that is not a cron IMHO... Actually you only need to run it when you application finishes booting. Thus, listen to the application booted event, and run your code then. For example, this one: Running code after Spring Boot starts

ch271828n
- 15,854
- 5
- 53
- 88