Historically, most scheduled tasks in Java applications I’ve worked on have used Spring’s scheduling https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/scheduling.html#scheduling-annotation-support-scheduled. Spring handles methods that you annotate with @Scheduled in the background of the application.
This creates a problem in the way scheduled tasks have been used historically: Because scheduled tasks are run in the background of the application, we have duplicated (and possibly competing) scheduled tasks as we horizontally scale the application.
n scheduled tasks duplicating the same scheduled task logic, which could cause duplicated logic, https://thenewstack.io/how-to-deal-with-race-conditions/ and inefficient use of resources.
We can overcome these disadvantages by separating the concerns of running the scheduled task and serving the application.