O'Reilly logo

Hands-On High Performance with Spring 5 by Dinesh Radadiya, Prashant Goswami, Pritesh Shah, Subhash Shah, Chintan Mehta

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

TaskScheduler

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required