Spring Boot - infinite loop service

Do not implement an infinite loop yourself. Let the framework handle it using its task execution capabilities:

@Service
public class RecordChecker{

    //Executes each 500 ms
    @Scheduled(fixedRate=500)
    public void checkRecords() {
        //Check states and send mails
    }
}

Don't forget to enable scheduling for your application:

@SpringBootApplication
@EnableScheduling
public class Application {

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

See also:

  • Scheduling Tasks

What I'm using is a message broker and a consumer put at the spring boot application to do the job.