2016-06-30 23:32 GMT+09:00 Nir Dweck <n...@vasco-de.com>:

> I am using tomcat connection  pool (tomcat 7) in my application (java
> application) to connect to a remote Oracle DB on an Azure machine. My
> connection pool configuration is as follow:
>
>     PoolProperties p = new PoolProperties();
>     p.setUrl(connString);
>     p.setUsername(user);
>     p.setPassword(password);
>     p.setDriverClassName("oracle.jdbc.OracleDriver");
>     p.setValidationQuery("SELECT 1 from dual");
>     p.setValidationInterval(1 * 60000/2);
>     p.setTimeBetweenEvictionRunsMillis(1 * 60000/2);
>     p.setTestOnBorrow(true);
>     p.setTestWhileIdle(true);
>     p.setMinIdle(10);
>     p.setInitialSize(10);
> However looking at the capture file, I see that the connections are not
> checked every 30 seconds as I expected. One connection is checked
> correctly, the others are checked after 3 times the configuration (180
> second). then again only some of the connections are checked and after a
> while it seems to stable on twice the configuration period (every 60
> seconds).
>
> I tested it with different configured time and different pool size, all
> had a instability period in which each time only part of the connections
> were checked and eventually it stabled on checks of all the connections
> every twice the configured time.
> What am I missing?
> Thanks,
>

I reproduced this.

I found the following code in the
org.apache.tomcat.jdbc.pool.ConnectionPool.
===
protected static class PoolCleaner extends TimerTask {
// snip

@Override
public void run() {
    ConnectionPool pool = this.pool.get();
    if (pool == null) {
        stopRunning();
    } else if (!pool.isClosed() &&
            (System.currentTimeMillis() - lastRun) > sleepTime) {
        lastRun = System.currentTimeMillis();
        try {
        // snip
===
Regardless of the scheduled PoolCleaner, (System.currentTimeMillis() -
lastRun) > sleepTime) is called.

Since PoolCleaner has been scheduled by the Timer#scheduleAtFixedRate,
This code probably is necessary in order to avoid a continuous calling of
PoolCleaner when the previous task was delayed.
However, This code causes the unintended skip of PoolCleaner.

I plan to fix the followings if there is no objection.
-Remove the "System.currentTimeMillis() - lastRun) > sleepTime".
-The scheduleAtFixedRate method changes to the schedule method.




>
> Nir
>
> --
> Keiichi.Fujino
>

Reply via email to