Skip to content

Commit

Permalink
Make sure the pool has been properly configured when attributes that …
Browse files Browse the repository at this point in the history
…related to the pool size are changed via JMX.

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1697571 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Keiichi Fujino committed Aug 25, 2015
1 parent 86eb14a commit f9d4874
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
Expand Up @@ -416,26 +416,7 @@ protected void init(PoolConfiguration properties) throws SQLException {
poolProperties = properties;

//make sure the pool is properly configured
if (properties.getMaxActive()<1) {
log.warn("maxActive is smaller than 1, setting maxActive to: "+PoolProperties.DEFAULT_MAX_ACTIVE);
properties.setMaxActive(PoolProperties.DEFAULT_MAX_ACTIVE);
}
if (properties.getMaxActive()<properties.getInitialSize()) {
log.warn("initialSize is larger than maxActive, setting initialSize to: "+properties.getMaxActive());
properties.setInitialSize(properties.getMaxActive());
}
if (properties.getMinIdle()>properties.getMaxActive()) {
log.warn("minIdle is larger than maxActive, setting minIdle to: "+properties.getMaxActive());
properties.setMinIdle(properties.getMaxActive());
}
if (properties.getMaxIdle()>properties.getMaxActive()) {
log.warn("maxIdle is larger than maxActive, setting maxIdle to: "+properties.getMaxActive());
properties.setMaxIdle(properties.getMaxActive());
}
if (properties.getMaxIdle()<properties.getMinIdle()) {
log.warn("maxIdle is smaller than minIdle, setting maxIdle to: "+properties.getMinIdle());
properties.setMaxIdle(properties.getMinIdle());
}
checkPoolConfiguration(properties);

//make space for 10 extra in case we flow over a bit
busy = new LinkedBlockingQueue<>();
Expand Down Expand Up @@ -502,6 +483,29 @@ protected void init(PoolConfiguration properties) throws SQLException {
closed = false;
}

public void checkPoolConfiguration(PoolConfiguration properties) {
//make sure the pool is properly configured
if (properties.getMaxActive()<1) {
log.warn("maxActive is smaller than 1, setting maxActive to: "+PoolProperties.DEFAULT_MAX_ACTIVE);
properties.setMaxActive(PoolProperties.DEFAULT_MAX_ACTIVE);
}
if (properties.getMaxActive()<properties.getInitialSize()) {
log.warn("initialSize is larger than maxActive, setting initialSize to: "+properties.getMaxActive());
properties.setInitialSize(properties.getMaxActive());
}
if (properties.getMinIdle()>properties.getMaxActive()) {
log.warn("minIdle is larger than maxActive, setting minIdle to: "+properties.getMaxActive());
properties.setMinIdle(properties.getMaxActive());
}
if (properties.getMaxIdle()>properties.getMaxActive()) {
log.warn("maxIdle is larger than maxActive, setting maxIdle to: "+properties.getMaxActive());
properties.setMaxIdle(properties.getMaxActive());
}
if (properties.getMaxIdle()<properties.getMinIdle()) {
log.warn("maxIdle is smaller than minIdle, setting maxIdle to: "+properties.getMinIdle());
properties.setMaxIdle(properties.getMinIdle());
}
}

public void initializePoolCleaner(PoolConfiguration properties) {
//if the evictor thread is supposed to run, start it now
Expand Down
Expand Up @@ -531,12 +531,16 @@ public void setLogAbandoned(boolean logAbandoned) {
@Override
public void setMaxActive(int maxActive) {
getPoolProperties().setMaxActive(maxActive);
//make sure the pool is properly configured
pool.checkPoolConfiguration(getPoolProperties());
}


@Override
public void setMaxIdle(int maxIdle) {
getPoolProperties().setMaxIdle(maxIdle);
//make sure the pool is properly configured
pool.checkPoolConfiguration(getPoolProperties());

}

Expand All @@ -561,6 +565,8 @@ public void setMinEvictableIdleTimeMillis(int minEvictableIdleTimeMillis) {
@Override
public void setMinIdle(int minIdle) {
getPoolProperties().setMinIdle(minIdle);
//make sure the pool is properly configured
pool.checkPoolConfiguration(getPoolProperties());
}


Expand Down

0 comments on commit f9d4874

Please sign in to comment.