Is it a good idea to expose an endpoint via spring boot actuator (e.g. /shutdown) and destroy the application context and all registered beans in the Web Application?
I’m currently shutting down my service using a custom class that implements ApplicationListener and listens to the application events of type ContextClosedEvent. It waits for 'x' seconds to completely stop ThreadPoolExecutor. So the idea here is to pause the Connector and then wait for its thread pool to shut down before starting the destruction of the application context. Basically, it blocks the JVM shutdown to wait for Undertow to be finished with pending requests. So it stops accepting new requests, wait for all the active requests to complete, and then gracefully shut everything down. Also, I‘m returning Error 503 is any new request comes in within this time.
To achieve this, I’m using io.undertow.server.handlers.GracefulShutdownHandler and other Undertow’s standard API for handler configuration within my service to perform manual commands like pause/shutdown.
I have secured the actuator endpoint using Spring Management Security via application.properties
management.security.enabled=true
security.user.name=test
security.user.password=test
management.security.roles=ACTRADMIN
management.context-path=/manage
Just wondering have anyone used a similar such mechanism to shut down a spring boot application gracefully or think of any other more enhanced way of doing it.
Thanks
No responses yet.