tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject [Bug 53254] Support for purging connection pool
Date Fri, 18 May 2012 19:18:05 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=53254

--- Comment #2 from Mike Youngstrom <youngm@gmail.com> ---
Nice!  Thanks Filip!

For laughs here is the workaround implementation I created yesterday. :)

public void purge() throws Exception {
        long oldMaxAge = dataSource.getMaxAge();
        int oldMaxIdle = dataSource.getMaxIdle();
        int oldMaxActive = dataSource.getMaxActive();
        int oldMinEvictTime = dataSource.getMinEvictableIdleTimeMillis();
        PooledConnection connection = dataSource.getPooledConnection();
        IllegalStateException error = null;
        try {
            dataSource.setMaxActive(1);
            dataSource.setMaxIdle(1);
            dataSource.setMaxAge(1);
            dataSource.setMinEvictableIdleTimeMillis(1);
            int sec = 0;
            Thread.sleep(1001);
            while(dataSource.getActive() > 1 && sec < 29) {
                Thread.sleep(1000);
                sec++;
            }
            dataSource.checkIdle();
            if(dataSource.getActive() > 1) {
                error = new IllegalStateException("Closed all but
"+(dataSource.getActive()-1)+" connection(s) after 30 sec.  Try again.");
            }
            connection.close();
        } finally {
            dataSource.setMaxAge(oldMaxAge);
            dataSource.setMaxActive(oldMaxActive);
            dataSource.setMaxIdle(oldMaxIdle);
            dataSource.setMinEvictableIdleTimeMillis(oldMinEvictTime);
            if(error != null) {
                throw error;
            }
        }
    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message