Hav spring boot application, While invoking Shutdown hook @Predestroy method is called and application shutdown happens. But Logs are not printed in both console and file, sys out line after the log is printed. It seems, Looger console shutdown before the application/process shutodwn.
Suggest some work around to resolve the issue.
Shutdown script:
SET /P PID_FROM_FILE= < application.pid taskkill /pid %PID_FROM_FILE% /f
Gracefulshutdown hook class:
@Component
public class GracefulShutdownHook {
private static final Logger LOGGER = LogManager.getLogger(GracefulShutdownHook.class);
@Autowired
@Qualifier("inboundChannel")
MessageChannel inboundChannel;
@Autowired
@Qualifier("pollingExecutor")
ThreadPoolTaskExecutor pollingExecutor;
@PreDestroy
public void onDestroy() throws Exception {
LOGGER.log(Level.INFO, "Application shutdown Initiated"); // this log is not printed
System.out.println(""Application shutdown Initiated""); // Sys out is printed
LOGGER.log(Level.INFO, "Application shutdown Processing"); // this log is not printed
inboundChannel.send(new GenericMessage<String>"@'filesInChannel.adapter'.stop()"));
pollingExecutor.shutdown();
LOGGER.log(Level.INFO, "Application shutdown succesfully"); // not printed
}
@Bean
public ExitCodeGenerator exitCodeGenerator() {
return () -> 0;
}
}