Skip to content

rd-1-2022/rpt-spring-scheduling-tasks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic Spring Scheudling application

This project demonstrates Spring's scheduling functionality by scheduling a method to be executed every 5 seconds.

Code

To enable scheduling support in Spring, the annotation @EnableScheduling should be placed on the main application class.

@SpringBootApplication
@EnableScheduling
public class SchedulingTasksApplication {

    public static void main(String[] args) {
        SpringApplication.run(SchedulingTasksApplication.class);
    }
	
}

The method that is to be scheduled has the annotation @Scheduled with a time value for a fixed rate of executing the method

@Scheduled(fixedRate = 5000)
public void reportCurrentTime() {
    log.info("The time is now {}", dateFormat.format(new Date()));
}

Building and running

./mvnw spring-boot:run

You will see log output that contains the message

The time is now 16:27:31

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages