I have a Spring Boot application which runs a number of jobs at specific times of the day (configured by CRON). Now I find that the the application is running but the scheduled jobs are not getting executed. Is there any way to add a timeout to a task annotated with @Scheduled in Spring.
So that even if the job is blocked or waiting, it can be killed, so that the other threads are allowed to execute smoothly. The thread can wait for a specified time and then if the task has not completed, kill the thread.
I know I can increase the poolsize using:
Executors.newScheduledThreadPool();
But what happens if eventually all threads are blocked
I have looked through the forum, and saw solutions which mentioned using FutureTasks. Can this be applied to a task with @Scheduled annotation? Since the application is spring-boot there is no xml configuration either to configure a timeout.
You can use
TaskScheduler
to start and control tasks. In your@Configuration
class:After then, you can schedule your task in this way: