What is best way to schedule task in spring boot application

The simplest way to schedule tasks in Spring is to create method annotated by @Scheduled in spring managed bean. It also required @EnableScheduling in any @Configuration classes.

Spring tutorial


you should use quartz-scheduler and send mails at different time and send only once.- put this as a business logic in your code. Please see for spring boot -quartz integration https://github.com/davidkiss/spring-boot-quartz-demo


You can use crontab inside @Scheduled

 private AtomicInteger counter = new AtomicInteger(0);

@Scheduled(cron = "*/2 * * * * *")
public void cronJob() {
    int jobId = counter.incrementAndGet();
    System.out.println("Job " + new Date() + ", jobId: " + jobId);
}