0

I have a Problem with Apache Commons DBCP. The pool works, but before a random time (Hours), this stop in a loop. I have Threads in Java, and one of them connect to DB with a Sleep of 15 Seconds. this Thread, before de random time stop working, but isn't killed, and is paused waiting for a Connection in a infinite Loop.

This is the Attachment of my DBCP configuration:

    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(_configuracion.getClassName());
    basicDataSource.setUsername(_configuracion.getUser());
    basicDataSource.setPassword(_configuracion.getPassword());
    basicDataSource.setUrl("jdbc:mysql://" + _configuracion.getSocket() + "/" +     
    _configuracion.getNombreBd());

    basicDataSource.setValidationQuery("SELECT 1");
    basicDataSource.setTestOnBorrow(true);
    basicDataSource.setTestWhileIdle(true);
    basicDataSource.setTestOnReturn(false);
    basicDataSource.setTimeBetweenEvictionRunsMillis(1000 * 60 * 15);
    basicDataSource.setMinEvictableIdleTimeMillis(1000 * 60 * 2);
    basicDataSource.setNumTestsPerEvictionRun(10);

    basicDataSource.setRemoveAbandoned(true);
    basicDataSource.setRemoveAbandonedTimeout(60 * 60);


    _dataSource = basicDataSource;

The _dataSource Atributte is a Static atributte of my Database Class and this Class is called for the Threads.

private static DataSource _dataSource;

I don't know if i have a problem in the DBCP Configuration.

Please Help Me!

EDIT: This is the code that uses DataSource.

public CachedRowSet query(String sql) {

CachedRowSet datos = null;
Connection con;
ResultSet rs;
try {
    con = _dataSource.getConnection();
    Statement sentencia = con.createStatement();
    rs = sentencia.executeQuery(sql);

    datos = new CachedRowSetImpl();
    datos.populate(rs);
    rs.close();
    sentencia.close();
    con.close();



 } catch (Exception ex) {
    System.out.println("Error: " + ex.getMessage());
 }

return datos;

}

I discover before the DBCP Pool Stop Working , it has a SQL Exception, this Exception was captured, but the Pool Stop Working.

1 Answers1

0

Try using latest jar (commons-dbcp-1.4) use setValidationQueryTimeout

Put query timeout for your sql queries.