我正在尝试使用 Commons Pool 和 DBCP 实现连接池。我能够建立与数据库的连接,并且一切都按预期工作,除了流量压缩。
这是我的配置:
- Commons DBCP 1.4
- Commons Pool 1.6
- MySQL Connector Java 5.1.21
- Windows Server 2008 上的 MySQL Server 5.5
- Java 1.6
请考虑使用此代码段来实例化连接池:
private void setupDataSource(Hashtable<String, String> data) {
try
{
GenericObjectPool<Connection> pool = new GenericObjectPool<Connection>();
pool.setMinIdle(5);
pool.setMaxActive(-1);
pool.setTestOnBorrow(true);
pool.setTimeBetweenEvictionRunsMillis(5000);
pool.setMinEvictableIdleTimeMillis(300000);
Properties props = new Properties();
props.setProperty("user", "root");
props.setProperty("password", "password");
props.setProperty("useCompression", "true");
ConnectionFactory cf = new DriverConnectionFactory(new com.mysql.jdbc.Driver(),
"jdbc:mysql://" + ip + ":" + port,
props);
KeyedObjectPoolFactory<String, GenericObjectPool<Connection>> kopf =new GenericKeyedObjectPoolFactory<String, GenericObjectPool<Connection>>(null, 20, GenericObjectPool.WHEN_EXHAUSTED_GROW, 20, true, false);
PoolableConnectionFactory pcf = new PoolableConnectionFactory(cf,
pool,
kopf,
"Select 1;",
false,
true);
PoolingDriver pd = new PoolingDriver();
pd.registerPool("MyPool", pool);
}catch (Exception ex)
{
ex.printStackTrace();
}
}
然后,要获得连接,我使用:
Connection conn = java.sql.DriverManager.getConnection("jdbc:apache:commons:dbcp:MyPool");
首先,除了比较 MSQL 工具中的传出网络流量之外,还有其他方法可以检查压缩是否有效?
为了启用压缩需要改变什么?
谢谢你的帮助
库