<property name="hibernateProperties"> < property name="hibernateProperties" >
< props>
< prop key="hibernate.dialect">org.hibernate.dialect.Oracle9Dialect
< prop key="hibernate.show_sql">false
< prop key="hibernate.jdbc.fetch_size">50
< prop key="hibernate.jdbc.batch_size">25
< prop key="hibernate.proxool.xml">proxool.xml
< prop key="hibernate.proxool.pool_alias">pool1
< prop key="hibernate.cglib.use_reflection_optimizer">true
< prop key="hibernate.query.factory_class">net.sf.hibernate.hql.classic.ClassicQueryTranslatorFactory< /prop >
</ props>
< /property >
</property>
在数据库应用程序中,数据库连接的取得是一个耗费时间的动作,为了避免花费时间在连接的取得与关闭上,我们会将连接资源放置在一个池中,需要连接时就从池中取得,不需要连接时就将之放回池中,以求重复利用连接,连接池也担任连接数量、连接时间的控制等等动作。
Proxool 是一个开放源码的连接池,在使用与设置上都十分的方便,Proxool 最新的版本是0.8.3,您可以在以下的网址下载:
http://proxool.sourceforge.net/index.html
1、新建web-inf/proxool.xml配置连接池属性
proxool支持多配置方式如property,javabean等
< something-else-entirely >
< proxool >
< alias > oracle alias >
< driver-url > jdbc:oracle:thin:@130.51.65.10:1521:xxxxx driver-url >
< driver-class > oracle.jdbc.OracleDriver driver-class >
< driver-properties >
< property name ="user" value ="xxxxxxxx" />
< property name ="password" value ="xxxxx" />
driver-properties >
< maximum-connection-count > 100 maximum-connection-count >
< house-keeping-test-sql > select 1 from dual house-keeping-test-sql >
proxool >
something-else-entirely >
2)在web.xml中配置读取proxool.xml;这个相当于程序中使用
JAXPConfigurator.configure("proxool.xml", false)。
在web.xml文件中添加以下内容
< servlet-name > ServletConfigurator servlet-name >
< servlet-class > org.logicalcobwebs.proxool.configuration.ServletConfigurator servlet-class >
< init-param >
< param-name > xmlFile param-name >
< param-value > WEB-INF/proxool.xml param-value >
init-param >
< load-on-startup > 1 load-on-startup >
servlet >
< servlet >
< servlet-name > Admin servlet-name >
< servlet-class > org.logicalcobwebs.proxool.admin.servlet.AdminServlet servlet-class >
servlet >
3)获取连接参考org.logicalcobwebs.proxool.examples.Simple类。
下载的开包中有相应的文档说明。可以参考以下代码
Connection conn = null ;
try {
Class.forName( " org.logicalcobwebs.proxool.ProxoolDriver " );
// conn=DriverManager.getConnection("protest:oracle.jdbc.OracleDriver:jdbc:oracle:thin:@130.51.65.10:1521:gzjf","","");
conn = DriverManager.getConnection( " proxool.oracle " );
if (conn == null ) {
log.info( " 获取连接失败 " );
} else {
log.info( " 获得连接成功 " );
}
} catch (Exception e) {
log.error(e.toString());
}
return conn;
}
下面是监控方法:
4)web.xml中配置adminservlet:
adminservlet的作中是监控连接池的运行状况。
< servlet-name > Admin servlet-name >
< servlet-class > org.logicalcobwebs.proxool.admin.servlet.AdminServlet servlet-class >
servlet >
< servlet-mapping >
< servlet-name > Admin servlet-name >
< url-pattern > /Admin url-pattern >
servlet-mapping >
用http://localhots/web-name/Admin访问得到监控结果