Scheduled task with cron not working as expected
See original GitHub issueHello. I have a simple Spring Boot application in which I just included the spring-boot-admin-starter-client
(version 1.5.2). Everything works fine except for the scheduled method detailed below:
@Service
public class SomeService {
@Scheduled(cron = "${cron.task.say.hello}")
public void someMethod() {
System.out.println("Hello world!");
}
}
Being cron.task.say.hello: "* * * * * MON-FRI"
in the application.yml
file.
As you probably noticed it should print Hello world! every second but it doesn’t work. It prints the message every different periods of time. Sometimes it takes 30 seconds, sometimes 20, it varies.
The application´s entry point is below:
@EnableAsync
@EnableScheduling
@SpringBootApplication
public class SchedulerStarter {
public static void main(String[] args) throws IOException {
SpringApplication.run(SchedulerStarter.class, args);
}
}
Removing spring-boot-admin-starter-client
and then using spring-boot-starter
works as expected.
Not sure if this is a bug or maybe I’m missing a piece of the puzzle.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Top Reasons Your Cron Job Isn't Running - Airplane.dev
Top reasons your cron job isn't running · 1. Schedule errors · 2. Environmental incompatibilities · 3. Depleted resources · 4. Overlapping jobs....
Read more >Why is my crontab not working, and how can I troubleshoot it?
Check that cron is running ... If cron isn't running then your commands won't be scheduled ... ... There may be other methods;...
Read more >Cron job troubleshooting guide - Cronitor
What to do if your cron job doesn't run when expected · Validate your job schedule. Once you have found your job, verify...
Read more >Cron job not working as expected configured with Quartz ...
First scheduler which runs every 5 minute forever works well without any problem. ... I wondered why second expression get stops sometimes. cron...
Read more >Why crontab scripts are not working? - Ask Ubuntu
cron ignores PATH from that file, so runnning somecommand from your script will fail when run with cron, but work when run in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So basically it’s always a good idea to configure a TaskScheduler when using
@EnableSchduling
… Your TaskScheduler is picked up because of the name…From the Spring code:
Since the scheduler provided by the SBA client is very similiar to the default one from
@EnableScheduling
and doesn’t interfere when you are providing a custom one, I tend to not fix this issue.I agree. This wasn’t an issue of SBA client just lack of knowledge of Spring Scheduling from my side.
Thanks for the feedback!