tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mikusa <>
Subject Re: Reg: Connection pool stats
Date Fri, 08 Nov 2013 13:46:33 GMT
On Nov 7, 2013, at 11:58 PM, Anu Prab <> wrote:

>>> I am using Tomcat 7.0.42 and Tomcat jdbc pool.
>> Just to be perfectly clear, how are you using this?  With a <Resource/>
> tag in your Tomcat >configuration or are you creating the pool in your
> code?  Either way, include the necessary >config or code which shows how
> you've defined the pool.
> The pool configuration is in context.xml. A sample of the config looks like
> this:
>   <Resource name="jdbc/name"
>              auth="Container"
>              type="javax.sql.DataSource"
>              fairQueue="true"
>              factory="<customized-factory>"

What factory are you using?  It's important to share.  Without it we don't know which pool
you're using.

>              username="<username>"
>              password="<password>"
>              driverClassName="oracle.jdbc.OracleDriver"
>              url="<url>"
>              timeBetweenEvictionRunsMillis="1800000"
>              validationQuery="SELECT 1 from dual"
>              validationInterval="30000"
>              maxActive="50"
>              minIdle="4"
>              maxIdle="4"
>              maxWait="10000"
>              initialSize="4"
>              removeAbandonedTimeout="60"
>              removeAbandoned="true"
>              logAbandoned="false"

You should enable this so you're alerted if your application is not properly returning connections.

>              minEvictableIdleTimeMillis="600000"
>              initSQL="<initSQL>"

Is this SQL valid?  If for some reason this SQL was failing, it would cause your connection
count to go to zero.  Same with the validation query, although that looks OK.

>              testOnBorrow="false"
>              testOnReturn="false"
>              testWhileIdle="true"
>    />
>>> Once the pool is created
>>> with the default configuration, I obtained few connections from this
> pool.
>> Again, how are you obtaining connections?  Is this through JNDI or through
> direct access by >code in your application?  An example would be helpful.
> The connections are being obtained by the code through JNDI lookup. Here's
> the code sample:
> Context ctx = (Context)new InitialContext().lookup("java:comp/env/");
> DataSource ds = (DataSource)ctx.lookup("jdbc/name");
> ds.getConnection();
>>> But after certain amount of time, dataSource.getSize() shows the size as
> 0!
>> How are you determining this?  Are you looking at it in a debugger?  Do
> you have a direct >reference to the data source in your code?  If so, can
> you show an example?
> I am doing a lookup for the data source in the code. The lookup example is
> the same as above. The only addition is after getting the data source,
> dataSource.getSize() is invoked.

How long does it take for the size to go to zero?  When it does, what do the active and idle
counts show?  Are they zero too?

Also, what happens when you try to get a connection after the pool count has dropped to 0?
 Does it get a new connection?  Does it hang waiting?  Does it generate any error messages?

Is there any reason why you might be getting disconnected from the database side or from a
firewall in between your application and the database?


>> As a note, when used in Tomcat (i.e. you've configured it with a
> <Resource/> tag) you should >use JMX to monitor pool statistics.  Of course
> you can do this if you manually create the pool >(like in a public static
> void main app), but you'll need to make sure JMX is correctly setup in
>> your application.
>>> Is this the expected behavior? Please help me understand what is
> happening.
>> We can certainly help you with this, but were going to need more info.
> See my other >comments.
>>> Thanks in advance.
>>> -Anu
>>> Adding to the previous information, though the minIdle is set to a value
>>> greater than 0, size of the pool, number of idle connections and number
> of
>>> active connections, all these are displayed as 0!
>> Connection counts can legitimately go to zero under certain conditions.
> Are you seeing any >error or warning messages from the connection pool in
> your logs?
> No errors/warnings!
> -Anu
>> Dan

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message