
Database Connection Pool로 데이터 베이스 연결하는 커넥션 풀
여러개의 Connection을 하나의 Pool에 모아두어 관리
데이터 베이스 연결을 관리하고 효율적으로 재사용하기 위함
| Parameter | Default | Description |
|---|---|---|
| initialSize | 0 | 최초 connection pool 시작될 때 초기 Connection 개수 |
| maxTotal | 8 | 최대로 사용할 수 있는 Connection 개수 |
| maxIdle | 8 | Connection pool에 반납할 때 최대 유지될 수 있는 Connection 수 |
| minIdle | 0 | 최소한으로 유지될 Connection 수 |
| maxWaitMillis | indefinitely | 풀이 예외를 발생시키기 전에 연결이 반환될 때까지 대기하는 시간(밀리초 단위) |
| validationQuery | Connection pool에 Connection을 반환하기 전에 해당 풀의 연결여부를 확인mysql : select 1oracle : select 1 from dual | |
| testOnBorrow | true | pool에서 Connection을 사용하기 위해서(Connction pool에서 Connection 얻어올 때) 유효성 검사 여부 |
| testOnReturn | false | Connection을 pool에 반환할 때 유효성 검사 여부 |
| maxConnLifetimeMillis | -1 (무한대) | 커넥션의 최대 라이프타임을 지정 |
| lifo | true | 최근에 반환한 Connection을 가장 우선 대여해 줍니다. |
application.yml
spring: datasource: url: jdbc:mysql://localhost:3306/my_database username: user password: password driver-class-name: com.mysql.cj.jdbc.Driver type: org.apache.commons.dbcp2.BasicDataSource dbcp2: initial-size: 200 max-total: 200 max-idle: 200 min-idle: 200 test-on-borrow: true validation-query: SELECT 1해당하는 url, username, password 등 정보 입력