I want to build a headless application which will query the DB in infinite loop and perform some operations in certain conditions (e.g. fetch records with specific values and wh
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: