Graceful application shutdown with signal handling and ordered teardown
implementation com.philiprehberger:graceful-shutdownGraceful application shutdown with signal handling and ordered teardown.
implementation("com.philiprehberger:graceful-shutdown:0.1.4")
<dependency>
<groupId>com.philiprehberger</groupId>
<artifactId>graceful-shutdown</artifactId>
<version>0.1.4</version>
</dependency>
import com.philiprehberger.gracefulshutdown.*
val shutdown = gracefulShutdown {
timeout(30.seconds)
onShutdown("http", priority = 10) { server.stop() }
onShutdown("db", priority = 5) { dataSource.close() }
onError { name, err -> logger.error("$name failed: $err") }
}
shutdown.installShutdownHook()
val tracker = RequestTracker()
// In request handler:
tracker.track { handleRequest(req) }
| Function / Class | Description |
|---|---|
gracefulShutdown { } | Build a shutdown manager |
onShutdown(name, priority) { } | Register a shutdown handler |
ShutdownManager.trigger() | Trigger shutdown (idempotent) |
ShutdownManager.installShutdownHook() | Install JVM shutdown hook |
ShutdownManager.isShuttingDown() | Check if shutdown triggered |
RequestTracker | Track in-flight work |
RequestTracker.track { } | Track a block of work |
RequestTracker.awaitDrained(timeout) | Wait for all work to complete |
./gradlew test
./gradlew build
If you find this project useful: