Backends Java API Overview - Java — Google Cloud Platfor
Shutdown
Shutdown
When App Engine needs to turn down a backend instance, existing requests are given 30 seconds to complete, and new requests immediately return 404. The shutdown process may be triggered by a variety of planned and unplanned events, such as:
The shutdown hook always runs in a different thread, even if your app isn't marked threadsafe. Inside the shutdown hook, you can use interruptAllRequests() to cancel your request threads and API calls.
The following code sample demonstrates a basic shutdown hook:
LifecycleManager.getInstance().setShutdownHook(new ShutdownHook() {
public void shutdown() {
LifecycleManager.getInstance().interruptAllRequests();
}
});
Alternatively, the following sample demonstrates how to use the isShuttingDown() method:
while (haveMoreWork() &&
!LifecycleManager.getInstance().isShuttingDown()) {
doSomeWork();
saveState();
}
Read full article from Backends Java API Overview - Java — Google Cloud Platform