2012-10-09 4 views
2

c3p0 연결 풀링에이 문제가 있습니다. 새 c3p0입니다. c3p0 연결 풀링 전체 이벤트 연결이 닫혔습니다

이 2008R2 내가 사용하는 JDBC 드라이버가 jtds 라이브러리 MSSQL 나의 데스크탑 프로그램 사용 자바이며, 연결 풀링에 대해 나는 프로그램이 몇 시간 동안 실행되는 몇 가지 문제가 C3P0를

를 사용하는 프로그램이 붙어있다 풀에서 연결을 기다리고 있기 때문입니다.

연결 풀이 가득 차서 SQL 문을 실행할 수없는 것 같습니다. SQL 문 실행을 끝낼 때마다 이미 연결을 닫습니다.

c3p0과 동일한 문제가있는 사람이 있습니까?

참고 : 저는 ComboPooledDataSource를 사용하며 연결을 원할 때 ComboPooledDataSource, getConnection() 메서드를 사용합니다. ComboPooledDataSource에서이 getConnection() 메서드를 사용하면 유휴 연결이 발생합니까?

유휴 상태로 연결하는 방법은 무엇입니까? 왜냐하면 나는 연결을 할 때마다 이미 연결을 닫았 기 때문입니다.

감사합니다. 1. 플로우 데이터베이스 연결 데이터베이스 트랜잭션 2.for (연결 및 풀링을 얻기 위해) (실행 쿼리 문)

public final class DBConnection { 
private static DatabaseProperties dbProp; 
private static ComboPooledDataSource ds; 

private DBConnection(){} 

private static void create(){ 
    DatabaseProperties dp = getDatabaseProperties(); 
    boolean success = true; 

    do{ 
     try{ 
      ds = new ComboPooledDataSource(); 
      ds.setDriverClass("net.sourceforge.jtds.jdbc.Driver"); 
      ds.setJdbcUrl("jdbc:jtds:sqlserver://"+ dp.getIpaddr()+":"+dp.getPort()+ "/"+dp.getDbname();); 
      ds.setUser(dp.getUsername()); 
      ds.setPassword(dp.getPassword()); 

      ds.setMinPoolSize(3); 
      ds.setAcquireIncrement(1); 
      ds.setMaxPoolSize(20); 
     } catch (Exception ex) { 
      LoggerController.log(Level.SEVERE,"Database error on creating connection",ex,LoggerController.DATABASE); 
      success = false; 
     } 
    }while(!success); 
} 
public static ComboPooledDataSource getDataSource(){ 
    if(ds == null)create(); 

    return ds; 
} 

public static Connection getConnection(){ 
    Connection con = null; 
    try { 
     con = DBConnection.getDataSource().getConnection(); 
    } catch (SQLException ex) { 
     LoggerController.log(Level.SEVERE,"Database error on getting connection",ex,LoggerController.DATABASE); 
    } 

    return con; 
} 

public static void close(){ 
    ds.close(); 
} 
: 은 일반적으로 난 2 클래스가 : 여기

내가 사용하는 코드입니다

}

public class DBTrans { 
private DBTrans(){} 

public static DataTable executeQuery(String query) throws SQLException{ 
    DataTable dt = null; 
    Connection con = null; 
    try { 
     con = DBConnection.getConnection(); 
     Statement stmt = con.createStatement(); 
     ResultSet rs = stmt.executeQuery(query); 
     dt = new DataTable(rs); 
    } catch (SQLException ex) { 
     throw new SQLException("QUERY= ["+query+"]\n"+ex.getMessage()); 
    } 
    finally{ 
     if(con!=null){ 
      con.close(); 
     } 
    } 
    return dt; 
} 

public static int executeUpdate(String query) throws SQLException{ 
    int sql = 0; 
    Connection con = null; 
    try { 
     con = DBConnection.getConnection(); 
     Statement stmt = con.createStatement(); 
     sql = stmt.executeUpdate(query); 
     con.close(); 
    } catch (SQLException ex) { 
     throw new SQLException("QUERY=["+query+"]\n"+ex.getMessage()); 
    } 
    finally{ 
     if(con!=null){ 
      con.close(); 
     } 
    } 
    return sql; 
} 

}

+0

예외 추적은 무엇입니까? – Santosh

+0

아니요, 프로그램이 막혔습니다. 연결을 기다리고 있습니다. – Pichanz

+0

프로그램을 디버그/프로파일 한 적이 있습니까? – Alfabravo

답변

2

은 APPLIC 결국, 당신이 보여 코드를 감안할 때 연결 풀이 고갈 된 채로 (즉, 모든 연결이 되돌릴 수없는 상태로 체크 아웃 된 상태로) 연결이 누수 될 수 있습니다. 강력한 리소스 정리 숙어를 꾸준히 사용해야합니다. 참조 예 :

http://old.nabble.com/Re:-My-connections-are-all-idle...-p27691635.html

당신은 당신의 코드를 수정하면

안정적으로 편안히 앉 연결에, 문제가 계속 표시되는 경우, C3P0를 찾을 설정과 디버그 미 반환 연결이 있습니다. unreturnedConnectionTimeout을 임시로 설정하고 debugUnreturnedConnectionStackTraces를 사용하여 누설을 추적 할 수 있습니다. 당신의 자원 정리 코드를 수정하고, 문제가 사라지는 지 확인 먼저

http://www.mchange.com/projects/c3p0/index.html#unreturnedConnectionTimeout

http://www.mchange.com/projects/c3p0/index.html#debugUnreturnedConnectionStackTraces

하지만를 참조하십시오. debugUnreturnedConnectionStackTraces 캡처는 성능 드래그입니다. 이름에서 알 수 있듯이 디버깅하려면 일시적으로 사용해야합니다.

도움이 되었기를 바랍니다.

+0

hmmm .. 나는 주어진 연결로 이미 finally 문을 사용하여 연결을 닫습니다. 충분히 신뢰할 만합니까? – Pichanz

+0

오, 죄송합니다! close를 두 번 호출합니다. 한 번만 executeUpdate의 본문에 있지만 한 번은 finally에 다시 호출합니다. 나는 두 번째 전화를 보지 못했다. unreturnedConnectionTimeout 및 debugUnreturnedConnectionStackTraces를 시도하여 Connection 누설을 찾을 수 있는지 확인하십시오. –

+0

ooops, 메소드에 close()가 2 개 있다는 것을 인식하지 못했습니다. 도움을 주셔서 감사합니다. 지금 테스트 해 보겠습니다. 지금 연결 누수가 있는지 봅시다. 도움을 주셔서 감사합니다 – Pichanz

관련 문제