回复 6# xxzmxx public static void StartPool() { loadProperties (); initDataSource (); if(connectionPool != null) { ShutdownPool (); } try { GenericOb...
显示全部回复 6# xxzmxx public static void StartPool()
{
loadProperties ();
initDataSource ();
if(connectionPool != null)
{
ShutdownPool ();
}
try
{
GenericObjectPool connectionPool = new GenericObjectPool (null);
connectionPool.setMaxIdle(4);
connectionPool.setMaxWait(50000);
connectionPool.setMinIdle(2);
connectionPool.setMaxActive(4);
byte value = 2;
connectionPool.setWhenExhaustedAction(value);
ConnectionFactory connectionFactory = new DriverManagerConnectionFactory (
url,name,password);
new PoolableConnectionFactory (connectionFactory,connectionPool,
null,null,false,true);
Class.forName ("org.apache.commons.dbcp.PoolingDriver");
PoolingDriver driver = (PoolingDriver) DriverManager.getDriver ("jdbc:apache:commons:dbcp:");
driver.registerPool (poolname,connectionPool);
System.out.println ("-----Assembly connection pool----OK");
}catch (Exception e)
{
e.printStackTrace ();
}
}
收起