Creating @Scheduled services
Spring 5 still supports batch processes or service transactions whose executions are triggered by time, just like any timer-based applications. The following recipe highlights the creation of batched transactions that run inside the Spring MVC container.
Getting started
Open a project, ch08, and add the following time-driven @Service methods.
How to do it...
Scheduled services are usually used to implement batch processing that can run simultaneously with the request handlers. To create these types of services, follow these steps:
- To enable schedule-based transactions, create a context definition
SpringScheduledConfigwhich implementsorg.springframework.scheduling.annotation.SchedulingConfigurer. Apply the class-level annotation@EnableSchedulingand override the methodconfigureTasks()with the preferred configurations oforg.springframework.scheduling.concurrent.ThreadPoolTaskSchedulerinjected in it:
@Configuration @EnableScheduling public class SpringScheduledConfig...