Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Apache Dolphinscheduler Connection Lifecycle Management

From Leeroopedia


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

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment