PooledConnection

PooledConnection (풀링된 연결)

연결 풀 관리를 위한 훅(hooks)을 제공하는 객체입니다. PooledConnection 객체는 데이터 소스에 대한 물리적 연결을 나타내며, 애플리케이션이 사용을 마쳤을 때 연결이 닫히는 대신 재활용되어 만들어야 하는 연결 수를 줄입니다.

출처: Java API Reference

본문

애플리케이션 프로그래머는 PooledConnection 인터페이스를 직접 사용하지 않으며, 연결 풀링을 관리하는 중간 계층(middle tier) 인프라가 사용합니다. 애플리케이션이 DataSource.getConnection을 호출하면 Connection 객체를 반환받는데, 연결 풀링이 이루어질 때 그 Connection 객체는 사실 물리적 연결인 PooledConnection 객체에 대한 핸들입니다.

연결 풀 관리자(보통 애플리케이션 서버)는 PooledConnection 객체들의 풀을 유지합니다. 풀에 사용 가능한 PooledConnection 객체가 있으면 관리자는 그 물리적 연결에 대한 핸들인 Connection 객체를 반환하고, 없으면 ConnectionPoolDataSource의 getPoolConnection 메서드를 호출해 새 물리적 연결을 만듭니다.

애플리케이션이 연결을 닫으면 Connection의 close 메서드를 호출합니다. 연결 풀링이 이루어질 때, 연결 풀 관리자는 addConnectionEventListener로 자신을 등록했으므로 알림을 받아 PooledConnection 객체에 대한 핸들을 비활성화하고, PooledConnection 객체를 다시 사용할 수 있도록 연결 풀로 반환합니다.

대표적인 메서드

Connection getConnection() throws SQLException
void close() throws SQLException
void addConnectionEventListener(ConnectionEventListener listener)
void removeConnectionEventListener(ConnectionEventListener listener)
void addStatementEventListener(StatementEventListener listener)
void removeStatementEventListener(StatementEventListener listener)

더 알아보기 (Learn more)

Java 공식 API