2014-10-29 2 views
4

시작시 연결 풀을 설정할 예정이지만 시간 초과 오류로 인해 연결 풀을 설정해야하는 Java 클라이언트 서버가 있습니다. 이이 같은 문제에 너무 많은 스레드가 있지만 해결책으로 아래 JDK 7을 사용하는 날java.sql.SQLException : 클라이언트가 연결을 체크 아웃하려고 시도한 시간이 초과되었습니다.

오전 근무하지 않고하면 mchange 받는다는 의존성을

<dependency> 
    <groupId>com.mchange</groupId> 
    <artifactId>c3p0</artifactId> 
    <version>0.9.2.1</version> 
</dependency> 

jdbc.properties 여기

url=jdbc\:sqlserver\://server\\instance;databaseName\=db 
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver 
user=admin 
password=admin 
maxPoolSize=20 
minPoolSize=5 
acquireIncrement=5 

입니다 서버 시작시 연결 풀을 설정하는 DAO 클래스입니다.

public class ShareDocDAO { 
//.......... 
private static Connection getConnection() throws SQLException { 
     LOG.info("Getting DB connection"); 
     ComboPooledDataSource cpds = getPool(); 

     return cpds.getConnection(); //Line 36: 
    } 
private static ComboPooledDataSource getPool() { 
     if (pool!=null) { 
      return pool; 
     } 

     ComboPooledDataSource cpds = new ComboPooledDataSource(); 
     try { 
      Properties dbProperties = getDbProperties(); 

      //loads the jdbc driver 
      cpds.setDriverClass(dbProperties.getProperty("driver"));    
      cpds.setJdbcUrl(dbProperties.getProperty("url")); 
      cpds.setUser(dbProperties.getProperty("user")); 
      cpds.setPassword(dbProperties.getProperty("password")); 

      // the settings below are optional -- c3p0 can work with defaults 
      cpds.setMinPoolSize(Integer.valueOf(dbProperties.getProperty("minPoolSize"))); 
      cpds.setAcquireIncrement(Integer.valueOf(dbProperties.getProperty("acquireIncrement"))); 
      cpds.setMaxPoolSize(Integer.valueOf(dbProperties.getProperty("maxPoolSize"))); 
      cpds.setCheckoutTimeout(30000); 
      cpds.setIdleConnectionTestPeriod(10800); 
      cpds.setMaxIdleTime(21600); 
      LOG.info("cpds driver "+cpds.getDriverClass()+ " JDBC URL = "+cpds.getJdbcUrl() +" User = "+cpds.getUser()+ " Pwd = "+cpds.getPassword()+ " MinPoolSize "+cpds.getMinPoolSize() +" AcquireIncrement "+cpds.getAcquireIncrement() +" MaxPoolSize "+cpds.getMaxPoolSize()); 
     } catch (Exception ex) { 
      LOG.error("failed to create pool", ex); 
     } 
     pool = cpds; 
     return pool; 
    } 
} 

다음은 스택 트레이입니다

[Oct 29 11:58:22] SSLHandshake-3 | ERROR | com.dc.ssltunnel.server.ShareDocDAO | Error querying for User Information 
java.sql.SQLException: An attempt by a client to checkout a Connection has timed out. 
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118) 
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:77) 
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:687) 
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140) 
    at com.dc.ssltunnel.server.ShareDocDAO.getConnection(ShareDocDAO.java:36) 
    at com.dc.ssltunnel.server.ShareDocDAO.checkSerialNumber(ShareDocDAO.java:75) 
    at com.dc.ssltunnel.server.MainServer.retrieveOrCreateClient(MainServer.java:95) 
    at com.dc.ssltunnel.server.MainServerHandshakeThread.handshake(MainServerHandshakeThread.java:58) 
    at com.dc.ssltunnel.server.MainServerHandshakeThread.run(MainServerHandshakeThread.java:71) 
    at com.dc.ssltunnel.utilities.threading.ShutdownThreadPoolExecutor$1.run(ShutdownThreadPoolExecutor.java:36) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: com.mchange.v2.resourcepool.TimeoutException: A client timed out while waiting to acquire a resource from [email protected] -- timeout at awaitAvailable() 
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1416) 
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606) 
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526) 
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755) 
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682) 
    ... 12 more 
[Oct 29 11:58:22] SSLHandshake-3 | DEBUG | com.dc.ssltunnel.server.MainServerHandshakeThread | Handshake thread is done 
[Oct 29 11:58:22] SSLHandshake-3 | DEBUG | com.dc.ssltunnel.server.MainServerHandshakeThread | Handshake thread is done 
[Oct 29 11:58:22] SSLHandshake-1 | INFO | com.dc.ssltunnel.server.ShareDocDAO | Getting DB connection 
[Oct 29 11:58:22] SSLHandshake-1 | INFO | com.dc.ssltunnel.server.ShareDocDAO | Getting DB connection 
[Oct 29 11:58:22] SSLHandshake-3 | DEBUG | com.dc.ssltunnel.utilities.threading.ShutdownThreadPoolExecutor | RUNNABLE:removing total:2 
[Oct 29 11:58:22] SSLHandshake-3 | DEBUG | com.dc.ssltunnel.utilities.threading.ShutdownThreadPoolExecutor | RUNNABLE:removing total:2 
[Oct 29 11:58:22] SSLHandshake-1 | ERROR | com.dc.ssltunnel.server.ShareDocDAO | Error querying for User Information 
java.sql.SQLException: Connections could not be acquired from the underlying database! 
    at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118) 
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:689) 
    at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140) 
    at com.dc.ssltunnel.server.ShareDocDAO.getConnection(ShareDocDAO.java:36) 
    at com.dc.ssltunnel.server.ShareDocDAO.checkSerialNumber(ShareDocDAO.java:75) 
    at com.dc.ssltunnel.server.MainServer.retrieveOrCreateClient(MainServer.java:95) 
    at com.dc.ssltunnel.server.MainServerHandshakeThread.handshake(MainServerHandshakeThread.java:58) 
    at com.dc.ssltunnel.server.MainServerHandshakeThread.run(MainServerHandshakeThread.java:71) 
    at com.dc.ssltunnel.utilities.threading.ShutdownThreadPoolExecutor$1.run(ShutdownThreadPoolExecutor.java:36) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 
Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source. 
    at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1418) 
    at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606) 
    at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526) 
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:755) 
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:682) 
    ... 12 more 

누군가 내 구성/코드에 무슨 문제가 있습니까?

+0

다른 매개 변수에서이 매개 변수를 테스트하여 작동하는지 확인 했습니까? –

+0

예, 동일한 자격 증명을 사용하여 SQL Server 관리 스튜디오에 로그인 할 수 있었고 동일한 jdbc 속성으로 정상적으로 실행되는 다른 웹 응용 프로그램이 있습니다 – RanPaul

+0

아마도 네트워크 문제 일 수 있습니다.이 응용 프로그램을 시작하는 서버가 ' 핑 (ping) '을 데이터베이스 서버에 보냅니다. –

답변

1

문제는 직접 또는 간접적으로 호출되지 않습니다

Transaction.Begin()이 일반적이다. 이 문제는 세션, SessionFactory 또는 구성에 문제가 될 수 있습니다.

세션 객체로 Query를 수행하여 디버그 할 수 있습니다. 테스트 객체가 작동하면 트랜잭션을 추가하고 begin(), commit() 적절하게