How to gracefully shutdown servelts in tomcat in docker container? How to gracefully shutdown servelts in tomcat in docker container? kubernetes kubernetes

How to gracefully shutdown servelts in tomcat in docker container?


Now I found the answer here: https://stackoverflow.com/a/11154770/2081279

It worked for me under linux with

<Context path="/myapp" unloadDelay="10000"/> 

but only with upper letter "C"ontext.


You could expose a REST API to stop gracefully the servers.

1) Implement and use a javax filter that maintains in its own state the HTTP requests in progress.
2) As the stop event occurs, the current tomcat instance doesn't have to serve any longer new clients requests. So make sure that new requests cannot be redirected to this instance.
3) As the stop event occurs (second thing), start a thread that waits for all requests were served. As all responses were sent, request the tomcat instance to shutdown : the command String shutdown may be a way.