On Nov 7, 2013, at 11:58 PM, Anu Prab <[email protected]> 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.
A customized factory which extends
org.apache.tomcat.jdbc.pool.DataSourceFactory
>> 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?
Few minutes, not sure of the exact timing. Yes, all are 0.
> 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?
I can still get newer connections even after the count drops to 0.
-Anu