dbcp.BasicDataSource – MBeanExporter – dataSourceMBean

db.test.on.borrow=true
db.min.idle=2
db.max.idle=-1
db.max.active=90
db.min.evict=60000
db.evict.frequency=6000

<bean id="dataSourceMBean" class="com.qbw.utilities.BasicDataSourceMBean">
<constructor-arg ref="dataDataSource" />
</bean>
<bean id="mbeanExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="DBCP:name=dataDataSource" value-ref="dataSourceMBean" />
</map>
</property>
</bean>

package com.qbw.tr.web.utilities;

import java.sql.SQLException;
import org.apache.commons.dbcp.BasicDataSource;
public class BasicDataSourceMBean {
private BasicDataSource dataSource;
public BasicDataSourceMBean(BasicDataSource dataSource) {
this.dataSource = dataSource;
}
/**
* The current number of active connections allocated from the managed datasource.
* @return The current number of active connections
*/
public int getNumActive() {
return dataSource.getNumActive();
}

/**
* The current number of idle connections waiting to be allocated from the managed datasource.
* @return The current number of active connections
*/
public int getNumIdle() {
return dataSource.getNumIdle();
}
/**
* <p>Returns the maximum number of active connections that can be allocated at the same time.
* </p>
* <p>A negative number means that there is no limit.</p>
*
* @return the maximum number of active connections
*/
public int getMaxActive() {
return dataSource.getMaxActive();
}
/**
* Sets the maximum number of active connections that can be
* allocated at the same time. Use a negative value for no limit.
*
* @param maxActive the new value for maxActive
*/
public void setMaxActive(int maxActive) {
dataSource.setMaxActive(maxActive);
}

/**
* <p>Returns the maximum number of connections that can remain idle in the pool.</p>
* <p>A negative value indicates that there is no limit</p>
*
* @return the maximum number of idle connections
*/
public int getMaxIdle() {
return dataSource.getMaxIdle();
}
/**
* Sets the maximum number of connections that can remain idle in the pool.
*
* @param maxIdle the new value for maxIdle
*/
public void setMaxIdle(int maxIdle) {
dataSource.setMaxIdle(maxIdle);
}

/**
* Returns the minimum number of idle connections in the pool.
*
* @return the minimum number of idle connections
*
*/
public int getMinIdle() {
return dataSource.getMinIdle();
}
/*
* Sets the minimum number of idle connections in the pool.
*
* @param minIdle the new value for minIdle
*
*/
public void setMinIdle(int minIdle) {
dataSource.setMinIdle(minIdle);
}
/**
* <p>Sets the maxWait property.</p>
* <p>Use -1 to make the pool wait indefinitely.</p>
*
* @param maxWait the new value for maxWait
* @see #getMaxWait()
*/
public void setMaxWait(long maxWait) {
dataSource.setMaxWait(maxWait);
}

public long getMaxWait() {
return dataSource.getMaxWait();
}
public long getMinEvictableIdleTimeMillis() {
return dataSource.getMinEvictableIdleTimeMillis();
}
public void setMinEvictableIdleTimeMillis(long val) {
dataSource.setMinEvictableIdleTimeMillis(val);
}
public void setMaxOpenPreparedStatements(int val) {
dataSource.setMaxOpenPreparedStatements(val);
}
public long getMaxOpenPreparedStatements() {
return dataSource.getMaxOpenPreparedStatements();
}
public void setLoginTimeout(int val) throws SQLException {
dataSource.setLoginTimeout(val);
}
public int getLoginTimeout() throws SQLException {
return dataSource.getLoginTimeout();
}
public void setPoolPreparedStatements(boolean val) {
dataSource.setPoolPreparedStatements(val);
}
public boolean isPoolPreparedStatements() {
return dataSource.isPoolPreparedStatements();
}

public void setNumTestsPerEvictionRun(int val) {
dataSource.setNumTestsPerEvictionRun(val);
}
public int getNumTestsPerEvictionRun() {
return dataSource.getNumTestsPerEvictionRun();
}
public void setTestOnBorrow(boolean val) {
dataSource.setTestOnBorrow(val);
}
public boolean getTestOnBorrow() {
return dataSource.getTestOnBorrow();
}
public void setTestOnReturn(boolean val) {
dataSource.setTestOnReturn(false);
}
public boolean getTestOnReturn() {
return dataSource.getTestOnReturn();
}
public void setTestWhileIdle(boolean val) {
dataSource.setTestWhileIdle(val);
}
public boolean getTestWhileIdle() {
return dataSource.getTestWhileIdle();
}

public void setTimeBetweenEvictionRunsMillis(long val) {
dataSource.setTimeBetweenEvictionRunsMillis(val);
}
public long getTimeBetweenEvictionRunsMillis() {
return dataSource.getTimeBetweenEvictionRunsMillis();
}
public int getCurrentPoolSize() {
return getNumActive()+getNumIdle();
}
}