Project successfully uses proxool connection pool

Source: Internet
Author: User
The connection pool technology is used in a recent project. The open source connection pools we are familiar with may include DBCP, c3p0, and proxool. For these three connection pools, proxool is slightly better than the first two in terms of performance and error rate. Today, I will briefly describe the configuration and source code that I have successfully configured in the project.

Step 1: first. Step 2: Write a separate proxool. xml file and place it in the WEB-INF folder. The configuration file of the mysql. peoxool. XML database is as follows: <? XML version = "1.0" encoding = "UTF-8"?>
<Proxool-config>
<Proxool>
<Alias> dB </alias>
<Driver-URL> JDBC: mysql: // ×××. ××. ××. ×××: 3303/mydb <driver-URL>
<Driver-class> com. MySQL. JDBC. Driver </driver-class>
<Driver-Properties>
<Property name = "user" value = "root"/>
<Property name = "password" value = "*******"/>
</Driver-Properties>
<House-keeping-sleep-time> 90000 <Maximum-New-connections> 20 </maximum-New-connections>
<Prototype-count> 5 </prototype-count>
<Maximum-connection-count> 1000 </maximum-connection-count>
<Minimum-connection-count> 10 </minimum-connection-count>
</Proxool>
</Proxool-config> a simple explanation of the preceding configuration: 1. <alias>: alias for the connection pool, which is referenced in other files. Reference: (proxool. DB); 2. <driver-class> com. MySQL. JDBC. Driver </driver-class>
<Driver-Properties>
<Property name = "user" value = "root"/>
<Property name = "password" value = "root"/>
</Driver-Properties> you should be familiar with these configurations. Configure the driver and connection of the database. 3. Step 3: load and initialize the proxool. xml file. Because it is connected to the database and data is used by many other modules, you must first load it on the web. perform the following configuration in XML: If you previously loaded applicationcontext. XML uses: <listener>
<Listener-class>
Org. springframework. Web. Context. contextloaderlistener
</Listener-class>
</Listener> in this case, you must replace the following configuration: <servlet>
<Servlet-Name> contextconfiglocation </servlet-Name>
<Servlet-class>
Org. springframework. Web. Context. contextloaderservlet
</Servlet-class>
<Load-on-startup> 2 </load-on-startup>
</Servlet> otherwise, you will encounter the following error:
  1. Problem
  2. Org. logicalcobwebs. proxool. proxoolexception: attempt to refer to a unregistered pool by its
  3. Alias 'db'
If you have used proxool and spring integration, many of them have encountered such problems. In fact, this problem is obviously your proxool. XML is not loaded and initialized first. We should let it load first. The configuration should be as follows: <servlet>
<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> set the value of <load-on-startup> to 1. The smaller the value, the higher the value. The load is initialized first. It must be loaded before applicationcontext. xml. This step is critical and you must pay attention to it. Otherwise, you will encounter the above problems. Many adults have encountered such a problem on the Internet. As long as you use it, you will experience such a mistake. If this is the first time, you will be very confused. the above problem occurs during my first configuration, so that I can find out the problem after debugging. I hope you will not make such a mistake again. If you want to monitor the connection status of the database connection pool, you can simply configure it, because most of the function source code has been written, we only need simple configuration. <Servlet>
<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> A ISO-8859-1 problem may be reported if access is made. We generally use UTF-8, and gbk2312. the best solution is to rewrite adminservlet in the source code.
. Java. I just rewritten the source code. To solve this garbled problem. There may be other ways: simply use this method. Private void printdefinitionentry (servletoutputstream out, string name, string value) throws ioexception {
Out. println ("<tr> ");
Out. Print ("<TD width =/" 200/"valign =/" Top/"style =/" "+ style_caption +"/"> ");
Out. Print (name );
Out. println ("</TD> ");
If (value! = NULL ){
Out. Print ("<TD style =/" "+ style_data +"/"> ");
Out. Print (new string (value. getbytes ("ISO-8859-1"), "UTF-8 "));
} Else {
Out. Print ("<TD style =/" "+ style_no_data +"/"> off ");
}
Out. Print ("</TD> ");
Out. println ("</tr> ");
} The red part above is the modified part, and then the <servlet-class>
Com. Jack. servlet. adminservlet
</Servlet-class> in <servlet-class>, replace it with the class you changed.
Last step: integrate Spring and proxool. Configure the original data source in the applicationcontext. xml file as follows: <bean id = "datasource"
Class = "org. springframework. JDBC. datasource. drivermanagerdatasource">
<Property name = "driverclassname">
<Value> org. logicalcobwebs. proxool. proxooldriver </value>
</Property>
<Property name = "url">
<Value> proxool. DB </value>
</Property>
</Bean> This <property name = "url"> must be configured as an alias in proxool. xml. This is not needed elsewhere. It can also be integrated with hibernate. Integration with spring is relatively simple. The above configuration method is used. The configuration is complete, which is clear and simple. If you want to view the monitoring status, you can view the monitoring status at http: // www. ××××. com/admin. If you want to test locally, change the path. The above describes a successful configuration and successful application in the project. Hope to be helpful to friends who are interested in connection pool.

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.