June 2018
Intermediate to advanced
408 pages
11h 23m
English
Sometimes, we need to perform a task at fixed intervals, and this can be achieved with the Spring scheduler framework. In this section, we will see how we can schedule a task in Spring with the use of a few annotations.
Let's see a simple example of scheduling a task in the Spring application:
@Configuration@EnableSchedulingpublic class SpringSchedulingExample { private static final Logger LOGGER = Logger.getLogger(SpringSchedulingExample.class); @Scheduled(fixedDelay = 2000) public void scheduledTask() { LOGGER.info("Execute task " + new Date()); } public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( SpringSchedulingExample.class); String scheduledAnnotationProcessor ...Read now
Unlock full access