Summary: | Support for purging connection pool | ||
---|---|---|---|
Product: | Tomcat Modules | Reporter: | Mike Youngstrom <youngm> |
Component: | jdbc-pool | Assignee: | Tomcat Developers Mailing List <dev> |
Status: | RESOLVED FIXED | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | unspecified | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All | ||
Bug Depends on: | |||
Bug Blocks: | 53346 |
Description
Mike Youngstrom
2012-05-17 17:59:28 UTC
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; } } } |