I have 2 instances of my Spring boot application, I am using spring JPA. Cron scheduler run method every one hour which first, check if record is already updated, if it's updated it should skip and don't update, but it's updated anyway on both instances. How to implement, something like synchronized, allow to read only when something is done?
@Scheduled(cron = "0 0 * * * ?", zone = "Europe/Paris")
public void updateServers() {
applicationServerRepository.findAll().forEach(this::updateServerInfo);
}