Hibernate 连接池的三种配置方式 2

------------ProxoolConf.xml--------------------

xml 文件放在同级目录中
需要 proxool-0.8.3.jar

Xml代码 <embed height="15" width="14" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="always" quality="high" flashvars="clipboard=%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22gb2312%22%3F%3E%0A%3Csomething-else-entirely%3E%0A%3Cproxool%3E%0A%3Calias%3Epool1%3C%2Falias%3E%0A%3Cdriver-url%3E%0A%20%20%20jdbc%3Amysql%3A%2F%2Ftpdb%3A3306%2Ftpdb%0A%3C%2Fdriver-url%3E%0A%3Cdriver-class%3Ecom.mysql.jdbc.Driver%3C%2Fdriver-class%3E%0A%3Cdriver-properties%3E%0A%3Cproperty%20name%3D%22user%22%20value%3D%22username%22%2F%3E%0A%3Cproperty%20name%3D%22password%22%20value%3D%22password%22%2F%3E%0A%3Cproperty%20name%3D%22schema%22%20%20value%3D%22tpdb%22%2F%3E%20%20%3C!--%20%EF%BC%9F%EF%BC%9F%EF%BC%9F--%3E%0A%3C!--%20%E8%87%AA%E5%8A%A8%E9%87%8D%E8%BF%9E%20--%3E%0A%3Cproperty%20name%3D%22autoReconnect%22%20value%3D%22true%22%2F%3E%0A%3C%2Fdriver-properties%3E%0A%3C!--%20proxool%E8%87%AA%E5%8A%A8%E4%BE%A6%E5%AF%9F%E5%90%84%E4%B8%AA%E8%BF%9E%E6%8E%A5%E7%8A%B6%E6%80%81%E7%9A%84%E6%97%B6%E9%97%B4%E9%97%B4%E9%9A%94(%E6%AF%AB%E7%A7%92)%2C%0A%E4%BE%A6%E5%AF%9F%E5%88%B0%E7%A9%BA%E9%97%B2%E7%9A%84%E8%BF%9E%E6%8E%A5%E5%B0%B1%E9%A9%AC%E4%B8%8A%E5%9B%9E%E6%94%B6%2C%E8%B6%85%E6%97%B6%E7%9A%84%E9%94%80%E6%AF%81--%3E%0A%3Chouse-keeping-sleep-time%3E90000%3C%2Fhouse-keeping-sleep-time%3E%0A%3C!--%20%E6%8C%87%E5%9B%A0%E6%9C%AA%E6%9C%89%E7%A9%BA%E9%97%B2%E8%BF%9E%E6%8E%A5%E5%8F%AF%E4%BB%A5%E5%88%86%E9%85%8D%E8%80%8C%E5%9C%A8%E9%98%9F%E5%88%97%E4%B8%AD%E7%AD%89%E5%80%99%E7%9A%84%E6%9C%80%E5%A4%A7%E8%AF%B7%E6%B1%82%E6%95%B0%2C%E8%B6%85%E8%BF%87%E8%BF%99%E4%B8%AA%E8%AF%B7%E6%B1%82%E6%95%B0%E7%9A%84%0A%E7%94%A8%E6%88%B7%E8%BF%9E%E6%8E%A5%E5%B0%B1%E4%B8%8D%E4%BC%9A%E8%A2%AB%E6%8E%A5%E5%8F%97(%E6%AD%A3%E5%BC%8F%E5%BA%9310%EF%BC%8C%E6%B5%8B%E8%AF%95%E5%BA%931)--%3E%0A%3Cmaximum-new-connections%3E10%3C%2Fmaximum-new-connections%3E%0A%3C!--%20%E6%9C%80%E5%B0%91%E4%BF%9D%E6%8C%81%E7%9A%84%E7%A9%BA%E9%97%B2%E8%BF%9E%E6%8E%A5%E6%95%B0(%E6%AD%A3%E5%BC%8F%E5%BA%9310%EF%BC%8C%E6%B5%8B%E8%AF%95%E5%BA%931)--%3E%0A%3Cprototype-count%3E10%3C%2Fprototype-count%3E%0A%3C!--%20%E8%BF%9E%E6%8E%A5%E6%B1%A0%E5%85%81%E8%AE%B8%E7%9A%84%E6%9C%80%E5%A4%A7%E8%BF%9E%E6%8E%A5%E6%95%B0(%E6%AD%A3%E5%BC%8F%E5%BA%93700%EF%BC%8C%E6%B5%8B%E8%AF%95%E5%BA%9310)--%3E%0A%3Cmaximum-connection-count%3E700%3C%2Fmaximum-connection-count%3E%0A%3C!--%20%E8%BF%9E%E6%8E%A5%E6%B1%A0%E5%BC%80%E5%90%AF%E7%9A%84%E6%9C%80%E5%B0%8F%E8%BF%9E%E6%8E%A5%E6%95%B0(%E6%AD%A3%E5%BC%8F%E5%BA%93350%EF%BC%8C%E6%B5%8B%E8%AF%95%E5%BA%935)--%3E%0A%3Cminimum-connection-count%3E350%3C%2Fminimum-connection-count%3E%0A%3C!--%20%E4%B8%80%E4%B8%AA%E6%B4%BB%E5%8A%A8%E8%BF%9E%E6%8E%A5%E7%9A%84%E6%9C%80%E9%95%BF%E6%97%B6%E9%97%B415%E5%88%86%E9%92%9F%EF%BC%8C%E5%8D%95%E4%BD%8D%E6%AF%AB%E7%A7%92%20--%3E%0A%3Cmaximum-active-time%3E900000%3C%2Fmaximum-active-time%3E%0A%3C!--%20%E4%B8%80%E4%B8%AA%E8%BF%9E%E6%8E%A5%E7%9A%84%E6%9C%80%E9%95%BF%E6%B4%BB%E5%8A%A8%E6%97%B6%E9%97%B44%E5%B0%8F%E6%97%B6%EF%BC%8C%E5%8D%95%E4%BD%8D%E6%AF%AB%E7%A7%92%20--%3E%0A%3Cmaximum-connection-lifetime%3E14400000%3C%2Fmaximum-connection-lifetime%3E%0A%3C!--%20%E8%87%AA%E5%8A%A8%E6%A3%80%E6%9F%A5%E8%BF%9E%E6%8E%A5%E6%98%AF%E5%90%A6%E6%96%AD%E6%8E%89%E5%BC%80%E5%85%B3%20--%3E%0A%3Ctest-before-use%3Etrue%3C%2Ftest-before-use%3E%0A%3C!--%20%E8%87%AA%E5%8A%A8%E6%A3%80%E6%9F%A5%E8%BF%9E%E6%8E%A5%E6%98%AF%E5%90%A6%E6%96%AD%E7%9A%84%E6%B5%8B%E8%AF%95sql%E8%AF%AD%E5%8F%A5%20--%3E%0A%3Chouse-keeping-test-sql%3Eselect%20sysdate()%20from%20dual%3C%2Fhouse-keeping-test-sql%3E%0A%3C%2Fproxool%3E%0A%3C%2Fsomething-else-entirely%3E" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" lk_mediaid="lk_juiceapp_mediaPopup_1232348908237" lk_media="yes">
  1. <?xml version="1.0" encoding="gb2312"?>  
  2. <something-else-entirely>  
  3. <proxool>  
  4. <alias>pool1</alias>  
  5. <driver-url>  
  6.     jdbc:mysql://tpdb:3306/tpdb  
  7. </driver-url>  
  8. <driver-class>com.mysql.jdbc.Driver</driver-class>  
  9. <driver-properties>  
  10. <property name="user" value="username"/>  
  11. <property name="password" value="password"/>  
  12. <property name="schema"  value="tpdb"/>  <!-- ???-->  
  13. <!-- 自动重连 -->  
  14. <property name="autoReconnect" value="true"/>  
  15. </driver-properties>  
  16. <!-- proxool自动侦察各个连接状态的时间间隔(毫秒),  
  17. 侦察到空闲的连接就马上回收,超时的销毁-->  
  18. <house-keeping-sleep-time>90000</house-keeping-sleep-time>  
  19. <!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的  
  20. 用户连接就不会被接受(正式库10,测试库1)-->  
  21. <maximum-new-connections>10</maximum-new-connections>  
  22. <!-- 最少保持的空闲连接数(正式库10,测试库1)-->  
  23. <prototype-count>10</prototype-count>  
  24. <!-- 连接池允许的最大连接数(正式库700,测试库10)-->  
  25. <maximum-connection-count>700</maximum-connection-count>  
  26. <!-- 连接池开启的最小连接数(正式库350,测试库5)-->  
  27. <minimum-connection-count>350</minimum-connection-count>  
  28. <!-- 一个活动连接的最长时间15分钟,单位毫秒 -->  
  29. <maximum-active-time>900000</maximum-active-time>  
  30. <!-- 一个连接的最长活动时间4小时,单位毫秒 -->  
  31. <maximum-connection-lifetime>14400000</maximum-connection-lifetime>  
  32. <!-- 自动检查连接是否断掉开关 -->  
  33. <test-before-use>true</test-before-use>  
  34. <!-- 自动检查连接是否断的测试sql语句 -->  
  35. <house-keeping-test-sql>select sysdate() from dual</house-keeping-test-sql>  
  36. </proxool>  
  37. </something-else-entirely>  
<?xml version="1.0" encoding="gb2312"?> <something-else-entirely> <proxool> <alias>pool1</alias> <driver-url> jdbc:mysql://tpdb:3306/tpdb </driver-url> <driver-class>com.mysql.jdbc.Driver</driver-class> <driver-properties> <property name="user" value="username"/> <property name="password" value="password"/> <property name="schema" value="tpdb"/> <!-- ???--> <!-- 自动重连 --> <property name="autoReconnect" value="true"/> </driver-properties> <!-- proxool自动侦察各个连接状态的时间间隔(毫秒), 侦察到空闲的连接就马上回收,超时的销毁--> <house-keeping-sleep-time>90000</house-keeping-sleep-time> <!-- 指因未有空闲连接可以分配而在队列中等候的最大请求数,超过这个请求数的 用户连接就不会被接受(正式库10,测试库1)--> <maximum-new-connections>10</maximum-new-connections> <!-- 最少保持的空闲连接数(正式库10,测试库1)--> <prototype-count>10</prototype-count> <!-- 连接池允许的最大连接数(正式库700,测试库10)--> <maximum-connection-count>700</maximum-connection-count> <!-- 连接池开启的最小连接数(正式库350,测试库5)--> <minimum-connection-count>350</minimum-connection-count> <!-- 一个活动连接的最长时间15分钟,单位毫秒 --> <maximum-active-time>900000</maximum-active-time> <!-- 一个连接的最长活动时间4小时,单位毫秒 --> <maximum-connection-lifetime>14400000</maximum-connection-lifetime> <!-- 自动检查连接是否断掉开关 --> <test-before-use>true</test-before-use> <!-- 自动检查连接是否断的测试sql语句 --> <house-keeping-test-sql>select sysdate() from dual</house-keeping-test-sql> </proxool> </something-else-entirely>


============ 数据库名可以这样指定 ==============

Xml代码
  1. <property name="connection.url">  
  2.     jdbc:sqlserver://localhost:1433;DatabaseName=supermarket  
  3. </property>  
<property name="connection.url"> jdbc:sqlserver://localhost:1433;DatabaseName=supermarket </property>

==============URL 还可以传参数===================

Xml代码
  1. <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>  
  2. <property name="connection.url">  
  3. jdbc:mysql://localhost:3306/struts?useUnicode=true&characterEncoding=GBK  
  4. </property>  
<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property> <property name="connection.url"> jdbc:mysql://localhost:3306/struts?useUnicode=true&characterEncoding=GBK </property>
目前,proxool用法,被大部分人认为是最优秀的。



=========== 连接池监控 ===================
1.在web.xml中加上下面这段
        Xml代码 <embed height="15" width="14" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowscriptaccess="always" quality="high" flashvars="clipboard=%20%20%3Cservlet%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cservlet-name%3E%20proxool%20%3C%2Fservlet-name%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cservlet-class%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20org.logicalcobwebs.proxool.admin.servlet.AdminServlet%20%20%20%20%20%0A%0A%20%20%20%20%20%3C%2Fservlet-class%3E%0A%20%20%20%20%20%20%20%20%20%20%3C%2Fservlet%3E%0A%20%20%20%20%20%20%20%20%20%20%3Cservlet-mapping%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Cservlet-name%3E%20proxool%20%3C%2Fservlet-name%3E%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Curl-pattern%3E%20%2FAdmin%2Fproxool%2F%20%3C%2Furl-pattern%3E%0A%20%20%20%20%20%20%20%20%20%20%3C%2Fservlet-mapping%3E" src="http://www.javaeye.com/javascripts/syntaxhighlighter/clipboard_new.swf" lk_mediaid="lk_juiceapp_mediaPopup_1232348908242" lk_media="yes">
  1. <servlet>  
  2.                 <servlet-name> proxool </servlet-name>  
  3.                 <servlet-class>                 org.logicalcobwebs.proxool.admin.servlet.AdminServlet       
  4.   
  5.    </servlet-class>  
  6.         </servlet>  
  7.         <servlet-mapping>  
  8.                 <servlet-name> proxool </servlet-name>  
  9.                 <url-pattern> /Admin/proxool/ </url-pattern>  
  10.         </servlet-mapping>  
<servlet> <servlet-name> proxool </servlet-name> <servlet-class> org.logicalcobwebs.proxool.admin.servlet.AdminServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name> proxool </servlet-name> <url-pattern> /Admin/proxool/ </url-pattern> </servlet-mapping>

2.http://localhost:8080/testhibernate/Admin/proxool
就可以监控到连接池的状况了!

你可能感兴趣的:(Hibernate)