Solved

Cannot get a connection, pool exhausted

Posted on 2007-12-04
3
4,172 Views
Last Modified: 2013-12-15
Hi,
I'm getting the error "Cannot get a connection, pool exhausted" every time when i try to cal a function in my Struts Action.
When first time accessing the first method of any DAO file, it is executing successfully where when i try to call a second method it showing the error:
"org.apache.commons.dbcp.SQLNestedException:Cannot get a connection, pool exhausted.
Caused by: java.util.NoSuchElementException: Timeout waiting for idle object"

I have released all the connection... Please help me in this regard.

Below my DAO file:

public LinkedList getListarUsuariosCelula(Conexao conexao, int idCelula) throws Exception {

            PreparedStatement stmt = null;
            ResultSet rs = null;
            LinkedList list = new LinkedList();
            int[] idUsuarios = new int[15];


            try {
                  stmt = conexao.getConnection().prepareStatement(STMT_USUARIO_CELULA);
                  stmt.setInt(1, idCelula);
                  rs = stmt.executeQuery();

                  for (int i = 0; rs.next(); i++) {
                        idUsuarios[i] = rs.getInt("idUsuario");
                  }

                  for (int i = 0; i < idUsuarios.length; i++) {
                        stmt = conexao.getConnection().prepareStatement(STMT_USUARIO_CELULA_IDUSUARIOS);
                        stmt.setInt(1, idUsuarios[i]);
                        rs = stmt.executeQuery();

                        while(rs.next()){
                              UsuarioGCA  usuarioGCA = new UsuarioGCA();

                              usuarioGCA.setNome(rs.getString("nome"));
                              usuarioGCA.setChave(rs.getString("chave"));

                              list.add(usuarioGCA);
                        }
                  }
            } catch (SQLException e) {
                  e.printStackTrace();
                  throw e;
            } finally {
                  conexao.closeConnection(stmt, rs);
                  conexao.close();
            }
            return list;
      }


my Context.xml file:

<Context path="/gepla" reloadable="true" docBase="C:\eclipse\workspace\gepla" workDir="C:\eclipse\workspace\gepla\work">
      <Resource name="jdbc/gepla"  auth="Container" type="javax.sql.DataSource" scope="Shareable" removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"/>
      <ResourceParams name="jdbc/gepla">
            <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter>
            <parameter><name>url</name><value>jdbc:mysql://172.18.3.229:3306/gepla</value></parameter>
            <parameter><name>username</name><value>root</value></parameter>
            <parameter><name>password</name><value>root</value></parameter>
            <parameter><name>maxActive</name><value>20</value></parameter>
            <parameter><name>maxIdle</name><value>10</value></parameter>
            <parameter><name>maxWait</name><value>100</value></parameter>
      </ResourceParams>
      <Resource name="jdbc/gca"  auth="Container" type="javax.sql.DataSource" scope="Shareable"
      removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true"/>
      <ResourceParams name="jdbc/gca">
            <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
            </parameter>
            <parameter><name>driverClassName</name><value>com.mysql.jdbc.Driver</value></parameter>
            <parameter><name>url</name><value>jdbc:mysql://172.18.3.229:3306/gca</value></parameter>
            <parameter><name>username</name><value>root</value></parameter>
            <parameter><name>password</name><value>root</value></parameter>
            <parameter><name>maxActive</name><value>20</value></parameter>
            <parameter><name>maxIdle</name><value>10</value></parameter>
            <parameter><name>maxWait</name><value>100</value></parameter>
      </ResourceParams>
</Context>

Thanks.
0
Comment
Question by:lorenadourado
3 Comments
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
ID: 20439768
Try adding these settings...add the following code to ur xml file
<!-- To configure a DBCP DataSource so that abandoned dB connections are removed and recycled add the following paramater to the ResourceParams configuration for your DBCP DataSource Resource: -->

<parameter>
<name>removeAbandoned</name>
<value>true</value>
</parameter>

<!--Use the removeAbandonedTimeout parameter to set the number of
seconds a dB connection has been idle before it is considered abandoned. -->

<parameter>
<name>removeAbandonedTimeout</name>
<value>60</value>
</parameter>

<!--The logAbandoned parameter can be set to true if you want DBCP to log a stack trace of the code which abandoned the dB connection resources -->

<parameter>
<name>logAbandoned</name>
<value>true</value>
</parameter>

R.K
0

Featured Post

The New “Normal” in Modern Enterprise Operations

DevOps for the modern enterprise offers many benefits — increased agility, productivity, and more, but digital transformation isn’t easy, especially if you’re not addressing the right issues. Register for the webinar to dive into the “new normal” for enterprise modern ops.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question