#815: ShutdownService.kt

projectforge-business/src/main/kotlin/org/projectforge/ShutdownService.kt Kotlin @Service, projectforge-business/src/main/kotlin/org/projectforge/ShutdownService.kt 45 lines · 12 code · 28 comments · 5 blank

Purpose

Manages shutdown listeners and ensures they are executed in the correct order before the database connection is closed. Called by ProjectForgeApp during graceful shutdown.

Architecture

Implements a simple observer pattern: ShutdownListener implementations register with registerListener(). When shutdown() is called, all listeners are invoked in registration order via forEach. This ensures that services relying on database access (like Hibernate Search indexing) can flush their state before the DB pool closes.

Key Types

Lifecycle

Listeners registered during application startup via Spring bean initialization. At shutdown, ProjectForgeApp calls shutdown() on this service before closing the database connection pool, allowing listeners to perform final writes, index flushes, or cleanup.

Git History

868d6abb7 2026-01-01 2025 -> 2026
63081666f 2025-01-01 Source headers: 2024-> 2025
f8961fd66 2024-12-11 Shutdown handling improved: ShutdownService will shutdown services first before database goes down