Principle:Apache Dolphinscheduler Connection Lifecycle Management
| Knowledge Sources | |
|---|---|
| Domains | Connection_Management, Resource_Management |
| Last Updated | 2026-02-10 00:00 GMT |
Overview
An automatic connection lifecycle management system using Guava cache eviction policies and HikariCP pool shutdown to ensure timely cleanup of idle database connections.
Description
The Connection Lifecycle Management principle ensures that database connection pools are properly cleaned up when no longer needed. The system uses Guavas expireAfterAccess eviction policy on the DataSourceClientProvider cache: when a pooled client is not accessed for a configurable duration (DATASOURCE_CLIENT_EXPIRE_SECONDS), the RemovalListener automatically calls client.close() which invokes HikariDataSource.close() to release all pooled connections. This prevents connection leaks and excessive database connection consumption in long-running services.
Usage
Lifecycle management is automatic and transparent. The Guava cache handles eviction based on access patterns, and the RemovalListener ensures proper cleanup.
Theoretical Basis
The lifecycle management combines TTL-based Eviction with Resource Disposal:
// Cache configuration
cache = CacheBuilder.newBuilder()
.expireAfterAccess(EXPIRE_SECONDS, TimeUnit.SECONDS)
.removalListener(notification -> {
PooledDataSourceClient client = notification.getValue();
client.close(); // HikariDataSource.close() releases all connections
})
.build();
// Lifecycle:
// 1. First access: pool created and cached
// 2. Subsequent accesses: pool reused from cache, TTL refreshed
// 3. No access for EXPIRE_SECONDS: cache eviction triggered
// 4. RemovalListener: pool closed, all connections released