일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- Spring DataSource
- Get 연동
- Spring 업로드
- spring dwr
- mysql 이달의 마지막말
- properties 한글
- spring
- PHP 막대그래프
- JSON String
- mysql 이달의 첫날
- 객체를 JSON으로
- varStatus
- 스프링 dwr
- 배열 길이
- 오라클연동
- properties 아스키코드
- 컨트롤러 리다이렉트
- Spring DB
- function태그
- 아웃룩 미리보기 해제
- 스프링 아이바티스
- forTokens
- SpringMVC DWR
- JSTL
- gson
- Microsoft Outlook 미리보기 해제
- SimpleDateFormat
- 스프링 업로드
- ControllerClassNameHandlerMapping
- 자바 오라클 연동
- Today
- Total
Blue Morning's Dev Story
Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure 본문
Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
Blue Morning 2012. 5. 29. 16:26
### Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 353,678,680 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago. ### The error may exist in sql/cuMonitorSQL.xml ### The error may involve cuMonitor.selectCurrentCuInfo ### The error occurred while executing a query ### SQL: [쿼리내용] ### Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 353,678,680 milliseconds ago. The last packet sent successfully to the server was 1 milliseconds ago. ; SQL []; Communications link failure |
원인
MySQL은 디폴트 타임아웃 값을 가지고 있다. 만약 커넥션이 생성되고, 이 타임아웃 기간이 지날 동안 사용되지 않는다면 이 커넥션은 끊긴 것으로 간주하고 커넥션을 종료한다. 하지만 dbcp는 커넥션이 끊어졌음을 알아채지 못하고, 커넥션 요청이 있을 때 연결이 끊긴 커넥션을 돌려준다. 그래서 에러가 발생한다.
수정
DBCP configuration 에 다음 사항을 추가한다.
n validationQuery=”SELECT 1″
n testOnBorrow=”true”
n JDBC URL에 autoReconnect=true 추가
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" p:driverClassName="${jdbc.driver}" p:url="${jdbc.db_admindb.url}" p:username="${jdbc.username}" p:password="${jdbc.password}" p:validationQuery="SELECT 1" p:testOnBorrow="true"/> |
jdbc.db_gamedb.url=jdbc:mysql://[..URL..]?noAccessToProcedureBodies=true&useInformationSchema=true&autoReconnect=true |
설명
'autoReconnect'옵션을 주게 되면, 커넥션에 문제가 있을 경우 다시 접속하게 된다.
그러나, 이 경우에도 끊어진 후 처음 한번의 시도는 실패가 나게 된다(이때 문제가 있다는 것을 알게 되는 것이므로..).
이때는 추가적인 DBCP옵션인 'validationQuery'값의 설정으로 해결 가능하다.
- validationQuery="select 1" => MySQL의 경우
- validationQuery="select 1 from dual" => Oracle의 경우
어플리케이션에 커넥션을 리턴하기 전에 dbcp는 “SELECT 1”쿼리를 실행해서 해당 커넥션이 살아있는지 확인한다. 이 작업이 ‘validationQuery’ 이다.
testOnBorrow 를 설정함으로써 커넥션을 어플리케이션에 돌려주기 전에 dbcp가 체크하도록 한다.
기타 DBCP옵션
maxActive : 커넥션 풀이 제공할 최대 커넥션 개수
maxIdle : 사용되지 않고 풀에 저장될 수 있는 최대 커넥션 개수. 음수일 경우 제한이 없다.
maxWait : whenExhaustedAction 속성의 값이 1일 때 사용되는 대기 시간. 단위는 1/1000초이며, 0 보다 작을 경우 무한히 대기한다.
testOnBorrow : true일 경우 커넥션 풀에서 커넥션을 가져올 때 커넥션이 유효한지의 여부를 검사한다.
testWhileIdle : true일 경우 비활성화 커넥션을 추출할 때 커넥션이 유효한지의 여부를 검사해서 유효하지 않은 커넥션은 풀에서 제거한다.
timeBetweenEvctionRunsMillis : 사용되지 않은 커넥션을 추출하는 쓰레드의 실행 주기를 지정한다. 양수가 아닐 경우 실행되지 않는다. 단위는 1/1000 초이다.
minEvictableIdleTimeMillis : 사용되지 않는 커넥션을 추출할 때 이 속성에서 지정한 시간 이상 비활성화 상태인 커넥션만 추출한다. 양수가 아닌 경우 비활성화된 시간으로는 풀에서 제거되지 않는다. 시간 단위는 1/1000초이다.
'OpenSource > MyBatis/iBatis' 카테고리의 다른 글
Spring MVC에서 간단한 iBatis사용예제 (2) | 2009.09.02 |
---|---|
iBatis 주요 Tag (0) | 2009.08.31 |