How to configure the database connection pool of hibernate + proxool

Source: Internet
Author: User
  1. Next I will introduce how to useHibernate3.0 how to configure a persistent data layer solutionProxool0.8.3 database connection pool method.
  2. 1. SetProxool-0.8.3.jar and the jar files used to connect to the database are included in the classpath or WEB-INF/lib of your project. In this example, the MS sqlserver database is used.
  3. 2. In andHibernateCreate a proxoolconf. xml file in the. cfg. xml level directory and add the following file content:
  4. <?XML Version="1.0" Encoding="UTF-8"?>
  5. <Something-else-entirely>
  6. <Proxool>
  7. <Alias>Proxoolpool</Alias>
  8. <! --ProxoolOnly connections generated by yourself can be managed -->
  9. <Driver-URL>JDBC: Microsoft: sqlserver :/// 192.168.0.5: 1433;Databasename=Videopublish</Driver-URL>
  10. <Driver-class>Com. Microsoft. JDBC. sqlserver. sqlserverdriver</Driver-class>
  11. <Driver-Properties>
  12. <Property Name="User" Value="Jdbc_user"/>
  13. <Property Name="Password" Value="Memory"/>
  14. </Driver-Properties>
  15. <! --ProxoolThe time interval (in milliseconds) for automatic reconnaissance of Various connection States. When detecting idle connections, the system immediately recycles them and destroys connections that have timed out. -->
  16. <House-keeping-sleep-time>90000</House-keeping-sleep-time>
  17. <! -- Indicates the maximum number of requests waiting in the queue because no idle connections can be allocated. User connections exceeding the number of requests will not be accepted. -->
  18. <Maximum-New-connections>20</Maximum-New-connections>
  19. <! -- Minimum number of idle connections maintained -->
  20. <Prototype-count>5</Prototype-count>
  21. <! -- The maximum number of connections allowed. If the connection is exceeded, the requests are placed in the queue. the maximum number of waiting requests is determined by maximum-New-connections. -->
  22. <Maximum-connection-count>100</Maximum-connection-count>
  23. <! -- Minimum connections -->
  24. <Minimum-connection-count>10</Minimum-connection-count>
  25. </Proxool>
  26. </Something-else-entirely>
  27. 3. The above isProxoolThe required configuration file is as follows:HibernateThe configuration of the. cfg. xml file is also very simple. The file content is as follows:
  28. <?XML Version='1. 0' Encoding='Utf-8'?>
  29. <! DoctypeHibernate-Configuration public
  30. "-//Hibernate/HibernateConfiguration DTD 3.0 // en"
  31. "Http ://Hibernate.Sourceforge.net/Hibernate-Configuration-3.0.dtd">
  32. <Hibernate-Configuration>
  33. <Session-factory>
  34. <Property Name="Proxool. Pool_alias">Proxoolpool</Property>
  35. <Property Name="Proxool. Xml">Proxoolconf. xml</Property>
  36. <Property Name="Connection. provider_class">Org.Hibernate. Connection. proxoolconnectionprovider</Property>
  37. <Property Name="Connection. driver_class">Com. Microsoft. JDBC. sqlserver. sqlserverdriver</Property>
  38. <Property Name="Show_ SQL">True</Property>
  39. <Mapping Resource="Com/VP/persistent/pojo/users. HBM. xml" />
  40. <Mapping Resource="Com/VP/persistent/pojo/videoclasses. HBM. xml" />
  41. <Mapping Resource="Com/VP/persistent/pojo/videodiscuss. HBM. xml" />
  42. <Mapping Resource="Com/VP/persistent/pojo/videoinfo. HBM. xml" />
  43. </Session-factory>
  44. </Hibernate-Configuration>
  45. 4. The above is the configurationHibernate+ProxoolAs a solution for database connection poolCodeIn this example, a simple test code is provided as follows:
  46. <%
  47. LongR=0;
  48. For (intI=0; I<10000; I ++ ){
  49. Try {
  50. LongO=NewDate (). gettime ();
  51. SessionS=HSF. Currentsession ();
  52. UsersU=NewUsers ();
  53. U. setusername ("zhanglili ");
  54. U. setuseremail ("baidongli@gmail.com ");
  55. U. setusernickname ("Bai dongli ");
  56. U. setuserpassword ("1234567980123456789 ");
  57. U. setusersex ("male ");
  58. U. setusersigndate (new date ());
  59. TransactionTT=S. Begintransaction ();
  60. S. Save (U );
  61. TT. Commit ();
  62. UsersUser= (Users) S. Get (users. Class, new INTEGER (1 ));
  63. // Out. println (user. GetUserName ());
  64. LongN=NewDate (). gettime ();
  65. R + = n-o;
  66. } Catch (exception e ){
  67. Out. println (E. getmessage ());
  68. } Finally {
  69. HSF. closesession ();
  70. }
  71. }
  72. Out. println ("AVG= "+ R/10 );
  73. %>
  74. 5. Describe how to useProxool, Tomcat JNDI,HibernateAfter the built-in connection pool is configured, the above 10000 data records are inserted and read separately. The result is displayed.ProxoolThe performance is better than that of Tomcat JNDI, andHibernateYou don't need to mention it if it comes with it. The difference is very long. In sequence: 39265 ms/10000, 26013 ms/10000, and 50029 ms/10000.
  75. 6.HibernateThere are some solutions for configuring the connection pool, such as c3p0 and Apache DHCP. However, many comments on the Internet show that the performance of c3p0 is much lower under heavy load, apache DHCPHibernateThe author found a performance Bug During the test, so the support for hibernate3.0 has been removed. In contrast,ProxoolIs recommended by everyone. Many mature companies (such as Samsung) UseProxoolAs a solution.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.