Re: Cannot get a connection, pool exhausted

2007-04-23 Thread Larry Meadors

Simple question - are there more than 100 requests active when this happens?

Larry


On 4/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

Now instead of set connection static i just create a new one for each query to 
perform, so if there are concurrent queries it shouldn't cause any problem:


   private Connection getConnection() throws Exception {
 // get context: provides the starting point for resolution of names
 Context ctx = new InitialContext();
 if (ctx == null) {
   throw new Exception("No Context");
 }
 // retrieve datasource
 DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/xxDB");
 if (ds == null) {
   throw new Exception("No Datasource");
 }
 // return db connection
 return ds.getConnection();
   }

   public void doSomething() {
 Connection con = null;
 Statement stmt = null;
 try {
   // get connection
   con = getConnection();
   if (con == null) {
 throw new Exception("No Connection");
   }
   stmt = con.createStatement();
   stmt.executeUpdate("UPDATE yy SET `zz`=0 WHERE `ww`='oo'");
 }
 catch (Exception e1) {
   //
 }
 // close resources
 finally {
   try {
 stmt.close();
 stmt = null;
   }
   catch (Exception e2) {
 //
   }
   try {
 con.close();
 con = null;
   }
   catch (Exception e3) {
 //
   }
 }
   }

is there anything else i should change for getting the pool connection to work?
Thanks in advance.


-- Initial Header ---

From  : "[EMAIL PROTECTED]" [EMAIL PROTECTED]
To  : "users" users@tomcat.apache.org
Cc  :
Date  : Sat, 21 Apr 2007 10:08:21 +0200
Subject : Cannot get a connection, pool exhausted

> Hello,
> i'm trying to achieve DBCP with tomcat 5.5.9. I thought to have done things right since 
the application could connect to db, but after a night that the application was running, in 
the morning, in logs, i saw a lot of "Cannot get a connection, pool exhausted" 
errors.
> This is my configuration:
>
> SERVER.XML:
>
>  
>
>   
>   
>   
>
>  
>
>   
>
>   
>   
>  
>   
> 
> 
> 
> 
>   
>   
>   
>   
>
> CONTEXT.XML:
>
> 
>name="jdbc/xxDB"
> auth="Container"
> type="javax.sql.DataSource"
> maxActive="100"
> maxIdle="30"
> maxWait="1"
> username="user"
> password="pass"
> driverClassName="com.mysql.jdbc.Driver"
> url="jdbc:mysql://127.0.0.1:3306/xx_xx?autoReconnect=true"/>
> 
>
> WEB.XML:
>
>
> 
> http://java.sun.com/xml/ns/j2ee"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; version="2.4">
>   xx
>   
> xxx.ApplicationWatch
>   
>   
> htmlcontent
> xxx.HtmlContentServlet
>   
>   
> htmlcontent
> /htmlcontent.view
>   
>   
> DB Connection
> jdbc/xxDB
> javax.sql.DataSource
> Container
>   
>   
> Security Constraint
> 
>   Protected Area
>   /*
> 
> 
>   xx
> 
>   
>   
> BASIC
> Protected Area
>   
>   
> xx
>   
> 
>
> THE WAY I CONNECT TO DB (this is one of the 6-7 methods i have to do stuff on 
db):
>
>   private static Connection con = null;
>
>   private static Connection getConnection() throws Exception {
> // get context: provides the starting point for resolution of names
> Context ctx = new InitialContext();
> if (ctx == null) {
>   throw new Exception("No Context");
> }
> // retrieve datasource
> DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/xxDB");
> if (ds == null) {
>   throw new Exception("No Datasource");
> }
> // return db connection
> return ds.getConnection();
>   }
>
>   public static void doSomething() {
> Statement stmt = null;
> try {
>   // get connection
>   con = getConnection();
>   if (con == null) {
> throw new Exception("No Connection");
>   }
>   stmt = con.createStatement();
>   stmt.executeUpdate("UPDATE yy SET `zz`=0 WHERE `ww`='oo'");
> }
> catch (Exception e1) {
>   //
> }
> // close resources
> finally {
>   try {
> stmt.close();
> stmt = null;
>   }
>   catch (SQLException e2) {
> //
>   }
>   try {
> con.close();
> con = null;
>   }
>   catch (SQLException e3) {
> //
>   }
> }
>   }
>
> Anybody have a clue of what can be? any help appreciated.
>
>
>
> --
> Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom
> http://click.libero.it/infostrada
>
>
>
> -
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTE

Re: Cannot get a connection, pool exhausted

2007-04-23 Thread David Smith
What you have below looks good as far as I can tell.  Connections appear 
to be returned ASAP after using them.  Do all your calls to the database 
follow this pattern?  Are there any places where the connection isn't 
closed immediately and within a finally block?


As an aside, you can store the DataSource object once you've done the 
JNDI look-up for the first time.  That won't harm anything and might 
improve speed a little.


--David

[EMAIL PROTECTED] wrote:


Now instead of set connection static i just create a new one for each query to 
perform, so if there are concurrent queries it shouldn't cause any problem:


  private Connection getConnection() throws Exception {
// get context: provides the starting point for resolution of names
Context ctx = new InitialContext();
if (ctx == null) {
  throw new Exception("No Context");
}
// retrieve datasource
DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/xxDB");
if (ds == null) {
  throw new Exception("No Datasource");
}
// return db connection
return ds.getConnection();
  }

  public void doSomething() {
Connection con = null;
Statement stmt = null;
try {
  // get connection
  con = getConnection();
  if (con == null) {
throw new Exception("No Connection");
  }
  stmt = con.createStatement();
  stmt.executeUpdate("UPDATE yy SET `zz`=0 WHERE `ww`='oo'");
}
catch (Exception e1) {
  //
}
// close resources
finally {
  try {
stmt.close();
stmt = null;
  }
  catch (Exception e2) {
//
  }
  try {
con.close();
con = null;
  }
  catch (Exception e3) {
//
  }
}
  }

is there anything else i should change for getting the pool connection to work?
Thanks in advance.


-- Initial Header ---

From  : "[EMAIL PROTECTED]" [EMAIL PROTECTED]
To  : "users" users@tomcat.apache.org
Cc  : 
Date  : Sat, 21 Apr 2007 10:08:21 +0200

Subject : Cannot get a connection, pool exhausted

 


Hello,
i'm trying to achieve DBCP with tomcat 5.5.9. I thought to have done things right since 
the application could connect to db, but after a night that the application was running, 
in the morning, in logs, i saw a lot of "Cannot get a connection, pool 
exhausted" errors.
This is my configuration:

SERVER.XML:



  
  
  




  

  
 


  





 
 
 
 

CONTEXT.XML:


 


WEB.XML:



http://java.sun.com/xml/ns/j2ee"; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"; 
version="2.4">
 xx
 
   xxx.ApplicationWatch
 
 
   htmlcontent
   xxx.HtmlContentServlet
 
 
   htmlcontent
   /htmlcontent.view
 
 
   DB Connection
   jdbc/xxDB
   javax.sql.DataSource
   Container
 
 
   Security Constraint
   
 Protected Area
 /*
   
   
 xx
   
 
 
   BASIC
   Protected Area
 
 
   xx
 


THE WAY I CONNECT TO DB (this is one of the 6-7 methods i have to do stuff on 
db):

 private static Connection con = null;

 private static Connection getConnection() throws Exception {
   // get context: provides the starting point for resolution of names
   Context ctx = new InitialContext();
   if (ctx == null) {
 throw new Exception("No Context");
   }
   // retrieve datasource
   DataSource ds = (DataSource) ctx.lookup("java:comp/env/jdbc/xxDB");
   if (ds == null) {
 throw new Exception("No Datasource");
   }
   // return db connection
   return ds.getConnection();
 }

 public static void doSomething() {
   Statement stmt = null;
   try {
 // get connection
 con = getConnection();
 if (con == null) {
   throw new Exception("No Connection");
 }
 stmt = con.createStatement();
 stmt.executeUpdate("UPDATE yy SET `zz`=0 WHERE `ww`='oo'");
   }
   catch (Exception e1) {
 //
   }
   // close resources
   finally {
 try {
   stmt.close();
   stmt = null;
 }
 catch (SQLException e2) {
   //
 }
 try {
   con.close();
   con = null;
 }
 catch (SQLException e3) {
   //
 }
   }
 }

Anybody have a clue of what can be? any help appreciated.



--
Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom
http://click.libero.it/infostrada



-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


   




--
Passa a Infostrada. ADSL e Telefono senza limiti e senza canone Telecom
http://click.libero.it/infostrada



-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional command

Re: Cannot get a connection, pool exhausted

2007-04-21 Thread Rashmi Rubdi

On 4/21/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:


is there anything else i should change for getting the pool connection to work?
Thanks in advance.



Most of the best practices and common mistakes to avoid are covered
here: 
http://tomcat.apache.org/tomcat-5.0-doc/jndi-datasource-examples-howto.html
IMO, especially under: Random Connection Closed Exceptions

Also this http://jakarta.apache.org/commons/dbcp/configuration.html
provides additional documentation on the various parameters.

-Rashmi

-
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]