So basically my app does some processing of stuff in intervals every 1 second. I have to implement a SIGTERM signal to my app but I have to let the stuff that is currently being processed in app to FINISH and then the app can terminate. Therefore I'm looking for something like a try{}catch{} but for SIGTERM, I would do a sleep for few seconds and then let the SIGTERM terminate the app, is there something like that?
As far as I know @PreDestroy closes whole context and then leaves one bean annotated with it, executes it and then destroys.
Also the addShutdownHook() is a method to be run when shutting down app, but I just want my main processing to finish and then shutdown everything.
Is there a way to do it?
The scheduled tasks are handled by Spring's
TaskExecutoryou can configure it to set a max wait time before termination and set a flag to wait for the task on shutdown.You can configure the
TaskExecutorby creating a custom ThreadPoolTaskExecutor bean.For example:
Additionally, you can set the option for max wait time:
the reason behind this:
You can read more here