You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by virupaksha <vi...@hotmail.com> on 2004/01/14 04:14:57 UTC

Database pool full.

Dear All,

I am developing an application on resin-2.1.9 web server.
Connection to MYSQL Database is using JNDI. JNDI connection code is written in a class called DBService.
I am instantiating DBService class where ever i need database connection and getting connection using getConnection() method.

when user start working on  application, i m getting following errors,

Class:DBService. Method:getConnection() cann't open connection with full database pool(30)
Class:MonthReport. Method:SelectReportDetailNull() cann't open connection with full database pool(30)

it sounds like database pool is full, Whether i need to increase the pool size or optimize code in DBService database connection class.

for your reference below code  performs database connection.

--------------------------------------------------------------
public Connection getConnection()
    {
        java.sql.Connection con = null;
        javax.sql.DataSource ds=null;

        try{

            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            ds= (DataSource)envCtx.lookup("jdbc/training");
            con = ds.getConnection();
            
            }catch(Exception e){
        System.out.println("Class : DBService, Method : getConnection()"+e.getMessage());
        }
        return con;

    }//end of getConnection method
-------------------------------------------------------------------------

Your advice will be great help to optimize my application.

Thanks in advance.

Regards,
Viru

Re: Database pool full.

Posted by Raphaël di Cicco <ra...@atosorigin.com>.
I'm backing up what Max said about having a leak somewhere. We used to have
a lot of problems with pooling. We have about 50 database utility beans that
get a connection, perform action on the database then release the
connection.
We discovered that the leak came from one single method that didn't release
the connection. Once we corrected it, there was no more problems no matter
which scheme we use.

Raphaël

----- Original Message ----- 
From: "virupaksha" <vi...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, January 14, 2004 6:02 AM
Subject: Re: Database pool full.


> Dear Max,
>
> Yah, this problem occures after  visiting some pages,
> to use #1 strategy, whether I need to do any changes in configuration or
is
> there any other way?
>
> Thanks for your suggestions & immediate response,
>
> Regards,
> viru
>
>
> ----- Original Message -----
> From: "Max Cooper" <ma...@maxcooper.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Wednesday, January 14, 2004 12:30 PM
> Subject: Re: Database pool full.
>
>
> > My guess is that you have a connection leak somewhere. Does this problem
> > start occurring immediately, or does it only show up after visiting a
> number
> > of pages in the site?
> >
> > Various db pools have different ways of dealing with no connections
being
> > available. Often, you can configure which strategy to use. Here are 3
> > different strategies:
> >
> > 1. Wait until a connection becomes available.
> > 2. Fail if no connections are available (i.e. return null or throw an
> > exception).
> > 3. Grow the pool temporarily if there are no free connections.
> >
> > It is clear from the errors you are getting that your pool is currently
> > using strategy #2. I like #1 the best, because it is less likely that
> > requests will fail under load. But, you must be sure that you don't have
> any
> > connection leaks, because the app will eventually hang if you have
> > connection leaks and use strategy #1. Strategy #3 works, but you can run
> > still run out of connections in the database itself, so it can start to
> act
> > like strategy #2. This is one aspect of connection pooling that
important
> to
> > consider when developing web apps.
> >
> > But, it seems likely that you have leaks somewhere. Some of your
requests
> > are probably not returning their connections to the pool. It could be
that
> > you have exceptions that are being thrown and not releasing the
> connection,
> > or it could just be that you have non-exception logic paths that don't
> > return the connections. Some combination of code reviews, debugging,
etc.
> is
> > needed to track them down.
> >
> > Another thing to watch out for is requests that require more than 1
> > simultaneous connection. For instance, consider the situation where you
> have
> > a pool of 30 connections, 15 request handler threads, and a request that
> > requires 3 connections. If 15 of those requests come in at once, and
each
> > request handler thread grabs 2 connections, you will have deadlock as
all
> > the request handler threads wait forever for a third db connection to
> become
> > available (assuming you are using pooling strategy #1 above). The
solution
> > to this problem is to make sure that you don't have any requests that
> > require more than one simultaneous connection, or at least that your db
> > connection pool has enough connections to survive a flood of connection
> > hungry requests (e.g. have a pool of 45 connections in the example
> scenario
> > described above -- 3 conn/req * 15 threads = 45 connections in the
pool).
> > This may seem unlikely, but it is a problem I have faced in a production
> > system (and it wasn't easy to track down!). Another lister here
suggested
> a
> > good technique for ensuring that none of your requests require more than
1
> > simultaneous connection -- test your app with a pool of 1 connections.
> >
> > -Max
> >
> > ----- Original Message -----
> > From: "virupaksha" <vi...@hotmail.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Tuesday, January 13, 2004 7:14 PM
> > Subject: Database pool full.
> >
> >
> > Dear All,
> >
> > I am developing an application on resin-2.1.9 web server.
> > Connection to MYSQL Database is using JNDI. JNDI connection code is
> written
> > in a class called DBService.
> > I am instantiating DBService class where ever i need database connection
> and
> > getting connection using getConnection() method.
> >
> > when user start working on  application, i m getting following errors,
> >
> > Class:DBService. Method:getConnection() cann't open connection with full
> > database pool(30)
> > Class:MonthReport. Method:SelectReportDetailNull() cann't open
connection
> > with full database pool(30)
> >
> > it sounds like database pool is full, Whether i need to increase the
pool
> > size or optimize code in DBService database connection class.
> >
> > for your reference below code  performs database connection.
> >
> > --------------------------------------------------------------
> > public Connection getConnection()
> >     {
> >         java.sql.Connection con = null;
> >         javax.sql.DataSource ds=null;
> >
> >         try{
> >
> >             Context initCtx = new InitialContext();
> >             Context envCtx = (Context) initCtx.lookup("java:comp/env");
> >             ds= (DataSource)envCtx.lookup("jdbc/training");
> >             con = ds.getConnection();
> >
> >             }catch(Exception e){
> >         System.out.println("Class : DBService, Method :
> > getConnection()"+e.getMessage());
> >         }
> >         return con;
> >
> >     }//end of getConnection method
>
> -------------------------------------------------------------------------
> >
> > Your advice will be great help to optimize my application.
> >
> > Thanks in advance.
> >
> > Regards,
> > Viru
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Database pool full.

Posted by virupaksha <vi...@hotmail.com>.
Thanks max for your suggestions,
Yah, there was a connection leak in  a mthod, so that leades to system slow
down.
Now it's OK, I am monitoring my application performance ,
then, we are using Resin connection pool class. any more suggestions?

Regards,
Viru
----- Original Message -----
From: "Max Cooper" <ma...@maxcooper.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, January 14, 2004 4:04 PM
Subject: Re: Database pool full.


> We were using the Oracle connection pool implementation, and it is a
> configurable item on there. There is no config file, so we used a method
> call to set the strategy in that case. I would expect that other pool
> implementations might have different options and different configuration
> procedures. I'm not familiar with the MySQL config, or even if the pool
you
> are using is part of the MySQL driver package (or perhaps the pool is part
> of Resin?). What is the fully-qualified class name of the DataSource class
> you are using?
>
> -Max
>
> ----- Original Message -----
> From: "virupaksha" <vi...@hotmail.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Tuesday, January 13, 2004 9:02 PM
> Subject: Re: Database pool full.
>
>
> > Dear Max,
> >
> > Yah, this problem occures after  visiting some pages,
> > to use #1 strategy, whether I need to do any changes in configuration or
> is
> > there any other way?
> >
> > Thanks for your suggestions & immediate response,
> >
> > Regards,
> > viru
> >
> >
> > ----- Original Message -----
> > From: "Max Cooper" <ma...@maxcooper.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Wednesday, January 14, 2004 12:30 PM
> > Subject: Re: Database pool full.
> >
> >
> > > My guess is that you have a connection leak somewhere. Does this
problem
> > > start occurring immediately, or does it only show up after visiting a
> > number
> > > of pages in the site?
> > >
> > > Various db pools have different ways of dealing with no connections
> being
> > > available. Often, you can configure which strategy to use. Here are 3
> > > different strategies:
> > >
> > > 1. Wait until a connection becomes available.
> > > 2. Fail if no connections are available (i.e. return null or throw an
> > > exception).
> > > 3. Grow the pool temporarily if there are no free connections.
> > >
> > > It is clear from the errors you are getting that your pool is
currently
> > > using strategy #2. I like #1 the best, because it is less likely that
> > > requests will fail under load. But, you must be sure that you don't
have
> > any
> > > connection leaks, because the app will eventually hang if you have
> > > connection leaks and use strategy #1. Strategy #3 works, but you can
run
> > > still run out of connections in the database itself, so it can start
to
> > act
> > > like strategy #2. This is one aspect of connection pooling that
> important
> > to
> > > consider when developing web apps.
> > >
> > > But, it seems likely that you have leaks somewhere. Some of your
> requests
> > > are probably not returning their connections to the pool. It could be
> that
> > > you have exceptions that are being thrown and not releasing the
> > connection,
> > > or it could just be that you have non-exception logic paths that don't
> > > return the connections. Some combination of code reviews, debugging,
> etc.
> > is
> > > needed to track them down.
> > >
> > > Another thing to watch out for is requests that require more than 1
> > > simultaneous connection. For instance, consider the situation where
you
> > have
> > > a pool of 30 connections, 15 request handler threads, and a request
that
> > > requires 3 connections. If 15 of those requests come in at once, and
> each
> > > request handler thread grabs 2 connections, you will have deadlock as
> all
> > > the request handler threads wait forever for a third db connection to
> > become
> > > available (assuming you are using pooling strategy #1 above). The
> solution
> > > to this problem is to make sure that you don't have any requests that
> > > require more than one simultaneous connection, or at least that your
db
> > > connection pool has enough connections to survive a flood of
connection
> > > hungry requests (e.g. have a pool of 45 connections in the example
> > scenario
> > > described above -- 3 conn/req * 15 threads = 45 connections in the
> pool).
> > > This may seem unlikely, but it is a problem I have faced in a
production
> > > system (and it wasn't easy to track down!). Another lister here
> suggested
> > a
> > > good technique for ensuring that none of your requests require more
than
> 1
> > > simultaneous connection -- test your app with a pool of 1 connections.
> > >
> > > -Max
> > >
> > > ----- Original Message -----
> > > From: "virupaksha" <vi...@hotmail.com>
> > > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > > Sent: Tuesday, January 13, 2004 7:14 PM
> > > Subject: Database pool full.
> > >
> > >
> > > Dear All,
> > >
> > > I am developing an application on resin-2.1.9 web server.
> > > Connection to MYSQL Database is using JNDI. JNDI connection code is
> > written
> > > in a class called DBService.
> > > I am instantiating DBService class where ever i need database
connection
> > and
> > > getting connection using getConnection() method.
> > >
> > > when user start working on  application, i m getting following errors,
> > >
> > > Class:DBService. Method:getConnection() cann't open connection with
full
> > > database pool(30)
> > > Class:MonthReport. Method:SelectReportDetailNull() cann't open
> connection
> > > with full database pool(30)
> > >
> > > it sounds like database pool is full, Whether i need to increase the
> pool
> > > size or optimize code in DBService database connection class.
> > >
> > > for your reference below code  performs database connection.
> > >
> > > --------------------------------------------------------------
> > > public Connection getConnection()
> > >     {
> > >         java.sql.Connection con = null;
> > >         javax.sql.DataSource ds=null;
> > >
> > >         try{
> > >
> > >             Context initCtx = new InitialContext();
> > >             Context envCtx = (Context)
initCtx.lookup("java:comp/env");
> > >             ds= (DataSource)envCtx.lookup("jdbc/training");
> > >             con = ds.getConnection();
> > >
> > >             }catch(Exception e){
> > >         System.out.println("Class : DBService, Method :
> > > getConnection()"+e.getMessage());
> > >         }
> > >         return con;
> > >
> > >     }//end of getConnection method
> >
>
> -------------------------------------------------------------------------
> > >
> > > Your advice will be great help to optimize my application.
> > >
> > > Thanks in advance.
> > >
> > > Regards,
> > > Viru
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> > >
> > >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Database pool full.

Posted by Max Cooper <ma...@maxcooper.com>.
We were using the Oracle connection pool implementation, and it is a
configurable item on there. There is no config file, so we used a method
call to set the strategy in that case. I would expect that other pool
implementations might have different options and different configuration
procedures. I'm not familiar with the MySQL config, or even if the pool you
are using is part of the MySQL driver package (or perhaps the pool is part
of Resin?). What is the fully-qualified class name of the DataSource class
you are using?

-Max

----- Original Message ----- 
From: "virupaksha" <vi...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, January 13, 2004 9:02 PM
Subject: Re: Database pool full.


> Dear Max,
>
> Yah, this problem occures after  visiting some pages,
> to use #1 strategy, whether I need to do any changes in configuration or
is
> there any other way?
>
> Thanks for your suggestions & immediate response,
>
> Regards,
> viru
>
>
> ----- Original Message -----
> From: "Max Cooper" <ma...@maxcooper.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Wednesday, January 14, 2004 12:30 PM
> Subject: Re: Database pool full.
>
>
> > My guess is that you have a connection leak somewhere. Does this problem
> > start occurring immediately, or does it only show up after visiting a
> number
> > of pages in the site?
> >
> > Various db pools have different ways of dealing with no connections
being
> > available. Often, you can configure which strategy to use. Here are 3
> > different strategies:
> >
> > 1. Wait until a connection becomes available.
> > 2. Fail if no connections are available (i.e. return null or throw an
> > exception).
> > 3. Grow the pool temporarily if there are no free connections.
> >
> > It is clear from the errors you are getting that your pool is currently
> > using strategy #2. I like #1 the best, because it is less likely that
> > requests will fail under load. But, you must be sure that you don't have
> any
> > connection leaks, because the app will eventually hang if you have
> > connection leaks and use strategy #1. Strategy #3 works, but you can run
> > still run out of connections in the database itself, so it can start to
> act
> > like strategy #2. This is one aspect of connection pooling that
important
> to
> > consider when developing web apps.
> >
> > But, it seems likely that you have leaks somewhere. Some of your
requests
> > are probably not returning their connections to the pool. It could be
that
> > you have exceptions that are being thrown and not releasing the
> connection,
> > or it could just be that you have non-exception logic paths that don't
> > return the connections. Some combination of code reviews, debugging,
etc.
> is
> > needed to track them down.
> >
> > Another thing to watch out for is requests that require more than 1
> > simultaneous connection. For instance, consider the situation where you
> have
> > a pool of 30 connections, 15 request handler threads, and a request that
> > requires 3 connections. If 15 of those requests come in at once, and
each
> > request handler thread grabs 2 connections, you will have deadlock as
all
> > the request handler threads wait forever for a third db connection to
> become
> > available (assuming you are using pooling strategy #1 above). The
solution
> > to this problem is to make sure that you don't have any requests that
> > require more than one simultaneous connection, or at least that your db
> > connection pool has enough connections to survive a flood of connection
> > hungry requests (e.g. have a pool of 45 connections in the example
> scenario
> > described above -- 3 conn/req * 15 threads = 45 connections in the
pool).
> > This may seem unlikely, but it is a problem I have faced in a production
> > system (and it wasn't easy to track down!). Another lister here
suggested
> a
> > good technique for ensuring that none of your requests require more than
1
> > simultaneous connection -- test your app with a pool of 1 connections.
> >
> > -Max
> >
> > ----- Original Message -----
> > From: "virupaksha" <vi...@hotmail.com>
> > To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> > Sent: Tuesday, January 13, 2004 7:14 PM
> > Subject: Database pool full.
> >
> >
> > Dear All,
> >
> > I am developing an application on resin-2.1.9 web server.
> > Connection to MYSQL Database is using JNDI. JNDI connection code is
> written
> > in a class called DBService.
> > I am instantiating DBService class where ever i need database connection
> and
> > getting connection using getConnection() method.
> >
> > when user start working on  application, i m getting following errors,
> >
> > Class:DBService. Method:getConnection() cann't open connection with full
> > database pool(30)
> > Class:MonthReport. Method:SelectReportDetailNull() cann't open
connection
> > with full database pool(30)
> >
> > it sounds like database pool is full, Whether i need to increase the
pool
> > size or optimize code in DBService database connection class.
> >
> > for your reference below code  performs database connection.
> >
> > --------------------------------------------------------------
> > public Connection getConnection()
> >     {
> >         java.sql.Connection con = null;
> >         javax.sql.DataSource ds=null;
> >
> >         try{
> >
> >             Context initCtx = new InitialContext();
> >             Context envCtx = (Context) initCtx.lookup("java:comp/env");
> >             ds= (DataSource)envCtx.lookup("jdbc/training");
> >             con = ds.getConnection();
> >
> >             }catch(Exception e){
> >         System.out.println("Class : DBService, Method :
> > getConnection()"+e.getMessage());
> >         }
> >         return con;
> >
> >     }//end of getConnection method
>
> -------------------------------------------------------------------------
> >
> > Your advice will be great help to optimize my application.
> >
> > Thanks in advance.
> >
> > Regards,
> > Viru
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: struts-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Database pool full.

Posted by virupaksha <vi...@hotmail.com>.
Dear Max,

Yah, this problem occures after  visiting some pages,
to use #1 strategy, whether I need to do any changes in configuration or is
there any other way?

Thanks for your suggestions & immediate response,

Regards,
viru


----- Original Message -----
From: "Max Cooper" <ma...@maxcooper.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Wednesday, January 14, 2004 12:30 PM
Subject: Re: Database pool full.


> My guess is that you have a connection leak somewhere. Does this problem
> start occurring immediately, or does it only show up after visiting a
number
> of pages in the site?
>
> Various db pools have different ways of dealing with no connections being
> available. Often, you can configure which strategy to use. Here are 3
> different strategies:
>
> 1. Wait until a connection becomes available.
> 2. Fail if no connections are available (i.e. return null or throw an
> exception).
> 3. Grow the pool temporarily if there are no free connections.
>
> It is clear from the errors you are getting that your pool is currently
> using strategy #2. I like #1 the best, because it is less likely that
> requests will fail under load. But, you must be sure that you don't have
any
> connection leaks, because the app will eventually hang if you have
> connection leaks and use strategy #1. Strategy #3 works, but you can run
> still run out of connections in the database itself, so it can start to
act
> like strategy #2. This is one aspect of connection pooling that important
to
> consider when developing web apps.
>
> But, it seems likely that you have leaks somewhere. Some of your requests
> are probably not returning their connections to the pool. It could be that
> you have exceptions that are being thrown and not releasing the
connection,
> or it could just be that you have non-exception logic paths that don't
> return the connections. Some combination of code reviews, debugging, etc.
is
> needed to track them down.
>
> Another thing to watch out for is requests that require more than 1
> simultaneous connection. For instance, consider the situation where you
have
> a pool of 30 connections, 15 request handler threads, and a request that
> requires 3 connections. If 15 of those requests come in at once, and each
> request handler thread grabs 2 connections, you will have deadlock as all
> the request handler threads wait forever for a third db connection to
become
> available (assuming you are using pooling strategy #1 above). The solution
> to this problem is to make sure that you don't have any requests that
> require more than one simultaneous connection, or at least that your db
> connection pool has enough connections to survive a flood of connection
> hungry requests (e.g. have a pool of 45 connections in the example
scenario
> described above -- 3 conn/req * 15 threads = 45 connections in the pool).
> This may seem unlikely, but it is a problem I have faced in a production
> system (and it wasn't easy to track down!). Another lister here suggested
a
> good technique for ensuring that none of your requests require more than 1
> simultaneous connection -- test your app with a pool of 1 connections.
>
> -Max
>
> ----- Original Message -----
> From: "virupaksha" <vi...@hotmail.com>
> To: "Struts Users Mailing List" <st...@jakarta.apache.org>
> Sent: Tuesday, January 13, 2004 7:14 PM
> Subject: Database pool full.
>
>
> Dear All,
>
> I am developing an application on resin-2.1.9 web server.
> Connection to MYSQL Database is using JNDI. JNDI connection code is
written
> in a class called DBService.
> I am instantiating DBService class where ever i need database connection
and
> getting connection using getConnection() method.
>
> when user start working on  application, i m getting following errors,
>
> Class:DBService. Method:getConnection() cann't open connection with full
> database pool(30)
> Class:MonthReport. Method:SelectReportDetailNull() cann't open connection
> with full database pool(30)
>
> it sounds like database pool is full, Whether i need to increase the pool
> size or optimize code in DBService database connection class.
>
> for your reference below code  performs database connection.
>
> --------------------------------------------------------------
> public Connection getConnection()
>     {
>         java.sql.Connection con = null;
>         javax.sql.DataSource ds=null;
>
>         try{
>
>             Context initCtx = new InitialContext();
>             Context envCtx = (Context) initCtx.lookup("java:comp/env");
>             ds= (DataSource)envCtx.lookup("jdbc/training");
>             con = ds.getConnection();
>
>             }catch(Exception e){
>         System.out.println("Class : DBService, Method :
> getConnection()"+e.getMessage());
>         }
>         return con;
>
>     }//end of getConnection method
> -------------------------------------------------------------------------
>
> Your advice will be great help to optimize my application.
>
> Thanks in advance.
>
> Regards,
> Viru
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


activeCount, useCount increasing automatically

Posted by shankarr <sh...@india.adventnet.com>.
Hi!
What is worrying me is that the number of activeCount and useCount are 
increasing though there have been no db interactions.
Any help, appreciated.

This is my data source entry from struts-config.xml file. Is there 
something wrong in it ?

   <data-sources>

     <data-source>
         <set-property property="driverClass" 
value="org.gjt.mm.mysql.Driver" />
         <set-property property="url" value="jdbc:mysql://localhost/" />
         <set-property property="maxCount" value="500"/>
         <set-property property="minCount" value="1"/>
         <set-property property="minIdle" value="10"/>
         <set-property property="testWhileIdle" value="true"/>
         <set-property property="timeBetweenEvictionRunsMillis" value="18000"/>
         <set-property property="testOnBorrow" value="true"/>
         <set-property property="maxActive" value="8"/>
         <set-property property="maxIdle" value="8"/>
         <set-property property="poolPreparedStatements" value="true"/>
         <set-property property="maxOpenPreparedStatements" value="2500"/>
         <set-property property="removeAbandoned" value="true"/>
         <set-property property="removeAbandonedTimeout" value="180"/>
         <set-property property="logAbandoned" value="true"/>
         <set-property property="validationQuery" value="select 1+1"/>
         <set-property property="user" value="root"/>
         <set-property property="password" value=""/>
     </data-source>

   </data-sources>

This is how I get my dbconnection in my action files

   Connection conn = null;
         Statement stmt = null;
         ResultSet rs = null;

         ServletContext context = servlet.getServletContext();
         DataSource dataSource = (DataSource) 
context.getAttribute(Action.DATA_SOURCE_KEY);
         String target = "success";
         conn = dataSource.getConnection();
         stmt = conn.createStatement();


I am getting the following in my tomcat prints.


INFO:    Found available connection
Jan 14, 2004 10:04:32 AM org.apache.struts.legacy.GenericDataSource 
getConnectio
n
INFO:    Return allocated connection, activeCount=29, useCount=29
Jan 14, 2004 10:04:34 AM org.apache.struts.legacy.GenericDataSource 
getConnectio
n
INFO:   getConnection()
Jan 14, 2004 10:04:34 AM org.apache.struts.legacy.GenericDataSource 
getConnectio
n
INFO:    Check for timeout, activeCount=29, useCount=29
Jan 14, 2004 10:04:34 AM org.apache.struts.legacy.GenericDataSource 
createConnec
tion
INFO:    createConnection()
Jan 14, 2004 10:04:34 AM org.apache.struts.legacy.GenericDataSource 
getConnectio
n
INFO:    Return new connection, activeCount=30, useCount=30
Jan 14, 2004 10:04:39 AM org.apache.struts.legacy.GenericDataSource 
getConnectio
n
INFO:   getConnection()
Jan 14, 2004 10:04:39 AM org.apache.struts.legacy.GenericDataSource 
getConnectio


Sha

Re: Database pool full.

Posted by Max Cooper <ma...@maxcooper.com>.
My guess is that you have a connection leak somewhere. Does this problem
start occurring immediately, or does it only show up after visiting a number
of pages in the site?

Various db pools have different ways of dealing with no connections being
available. Often, you can configure which strategy to use. Here are 3
different strategies:

1. Wait until a connection becomes available.
2. Fail if no connections are available (i.e. return null or throw an
exception).
3. Grow the pool temporarily if there are no free connections.

It is clear from the errors you are getting that your pool is currently
using strategy #2. I like #1 the best, because it is less likely that
requests will fail under load. But, you must be sure that you don't have any
connection leaks, because the app will eventually hang if you have
connection leaks and use strategy #1. Strategy #3 works, but you can run
still run out of connections in the database itself, so it can start to act
like strategy #2. This is one aspect of connection pooling that important to
consider when developing web apps.

But, it seems likely that you have leaks somewhere. Some of your requests
are probably not returning their connections to the pool. It could be that
you have exceptions that are being thrown and not releasing the connection,
or it could just be that you have non-exception logic paths that don't
return the connections. Some combination of code reviews, debugging, etc. is
needed to track them down.

Another thing to watch out for is requests that require more than 1
simultaneous connection. For instance, consider the situation where you have
a pool of 30 connections, 15 request handler threads, and a request that
requires 3 connections. If 15 of those requests come in at once, and each
request handler thread grabs 2 connections, you will have deadlock as all
the request handler threads wait forever for a third db connection to become
available (assuming you are using pooling strategy #1 above). The solution
to this problem is to make sure that you don't have any requests that
require more than one simultaneous connection, or at least that your db
connection pool has enough connections to survive a flood of connection
hungry requests (e.g. have a pool of 45 connections in the example scenario
described above -- 3 conn/req * 15 threads = 45 connections in the pool).
This may seem unlikely, but it is a problem I have faced in a production
system (and it wasn't easy to track down!). Another lister here suggested a
good technique for ensuring that none of your requests require more than 1
simultaneous connection -- test your app with a pool of 1 connections.

-Max

----- Original Message ----- 
From: "virupaksha" <vi...@hotmail.com>
To: "Struts Users Mailing List" <st...@jakarta.apache.org>
Sent: Tuesday, January 13, 2004 7:14 PM
Subject: Database pool full.


Dear All,

I am developing an application on resin-2.1.9 web server.
Connection to MYSQL Database is using JNDI. JNDI connection code is written
in a class called DBService.
I am instantiating DBService class where ever i need database connection and
getting connection using getConnection() method.

when user start working on  application, i m getting following errors,

Class:DBService. Method:getConnection() cann't open connection with full
database pool(30)
Class:MonthReport. Method:SelectReportDetailNull() cann't open connection
with full database pool(30)

it sounds like database pool is full, Whether i need to increase the pool
size or optimize code in DBService database connection class.

for your reference below code  performs database connection.

--------------------------------------------------------------
public Connection getConnection()
    {
        java.sql.Connection con = null;
        javax.sql.DataSource ds=null;

        try{

            Context initCtx = new InitialContext();
            Context envCtx = (Context) initCtx.lookup("java:comp/env");
            ds= (DataSource)envCtx.lookup("jdbc/training");
            con = ds.getConnection();

            }catch(Exception e){
        System.out.println("Class : DBService, Method :
getConnection()"+e.getMessage());
        }
        return con;

    }//end of getConnection method
-------------------------------------------------------------------------

Your advice will be great help to optimize my application.

Thanks in advance.

Regards,
Viru


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org