0

When the spring server shutdown, destroy method or the method with @PreDestroy annotation of registered beans get called. What I want is to control the execution by writing a method before even the first destroy method is called.

Use case - I want to wait for sometime before any of the beans get destroyed. This is to make the shutdown graceful.

Saurav Kumar Singh
  • 1,352
  • 7
  • 18
  • Could you elaborate on the **something** you need to wait for? – M. Deinum Apr 15 '21 at 06:42
  • 1
    Maybe [this](https://stackoverflow.com/questions/10902775/spring-shutdown-event-that-fires-immediately-before-applicationcontext-is-destro) is something you're looking for? – christianfoleide Apr 15 '21 at 08:36
  • @M.Deinum so the use case is basically is that, i will mark server unhealthy, other services in the service makes health check every 10s or so, hence I will delay the server shutdown by let say 20 sec, In that time other service will figure out that this server is not healthy anymore and no more request will come to this server.. so the list of healthy servers are eventual consistent on client side, shutting down instantly might result in lot of request failures. – Saurav Kumar Singh Apr 15 '21 at 09:26
  • BUt if this service is unhealthy how should it handle requests anyway? Shouldn't that be something that is handled on the calling side? But you could write a listener (don't use a predestroy method for that) that does that. – M. Deinum Apr 15 '21 at 09:48
  • marking service unhealthy doesn't mean that service is unhealthy. You generally expose a health check API which returns positive response when you want other services to consider this service healthy. If you want other services to notice that this service is not healthy anymore, you can force health check API to return negative response, however the service is still capable of handling requests.. – Saurav Kumar Singh Apr 15 '21 at 10:28
  • @christianfoleide the link is not helpful in this case... the question is about the interceptor to be triggered after all the beans are destroyed.. I need before that. – Saurav Kumar Singh Apr 15 '21 at 10:39

0 Answers0