I wrote below scheduler which runs everyday midnight 12 am. This has to restart the spring boot web application ( self ) and it is working as expected most of the time. But once in a week ( approximately), application shutdown happens successfully, but not starting up.
Because this is failing intermittently, I have no clue why this code failing.
In my eclipse IDE environment, it works almost everytime. ( I changed the scheduler to run every 5 mins)
@Service
final class AutoRestartScheduler {
@Autowired
private RestartEndpoint restartEndpoint; //private to protect outside access.
final Logger logger = LoggerFactory.getLogger(AutoRestartScheduler.class);
@Scheduled(cron = "0 0 0 * * *", zone="America/Los_Angeles") //everyday mid-night 12 AM PST
public void restartApp(){
logger.info("Going to restart Tomcat, programmatically.");
logger.info("restarting MyPollerApplication...");
restartEndpoint.restart();
}
}
NOTE:
I am NOT using below property in configuration, because I am NOT using Actuator's /restart endpoint but Spring's Scheduler.
management.endpoint.restart.enabled=true