Database connection pool summary-proxool

Source: Internet
Author: User
1. The proxool. jar file can be downloaded at http://sourceforge.net/projects/proxool.
2. Section 01 Why Connection Pooling

When
We have entered the Java Development World, and the pool is also a learning. How can we first establish a connection with the database for connection,
Later, people can use the connection that already exists in the pool to reduce the connection time. Such an excellent function is available in many applications.
Server has been implemented. You just need to configure the parameters according to the instruction file, including the maximum number of connections, the initial number of connections, and the maximum number of waits. Of course,
Tomcat also has a built-in Connection pooling mechanism related to commons-DBCP. For details, refer to Tomcat JNDI datasource settings !!

While
Proxool is a powerful connection pooling project that is compatible with JDK 1.3 and 1.4. It has also been monitored,
Recording and other functions are a complete solution for a project with limited connection quantity and performation emphasis.

Download Area, current version 0.7.2

Http://sourceforge.net/projects/proxool/

Section 02Set adminservlet

First, you need to download all the jar files under the Lib of proxool, put it under the WEB-INF/lib,

In addition, put your JDBC driver in the same Lib,

Then Configure/WEB-INF/Web. xml

 
Web. xml<? XML version = "1.0" encoding = "UTF-8"?> <! Doctype web-app public "-// Sun Microsystems, Inc. // DTD web application 2.3 // "/WEB-INF/dtds/web-app_2_3.dtd"> <web-app> <display-Name> proxool </display-Name> <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> </Web-app>

Section 03Get connection through proxooldriver

Create a JSP or Dao bean and use org. logicalcobwebs. proxool. proxooldriver to create a connection

Test. jsp<% @ Page import = "Java. SQL. * "%> <% connection = NULL; try {class. forname ("org. logicalcobwebs. proxool. proxooldriver "); connection = drivermanager. getconnection ("proxool. test: Org. gjt. mm. mySQL. driver: JDBC: mysql: // localhost: 3306/test "," root "," password ");} catch (exception e) {out. println (e)} Out. println ("OK"); %>

Section 04View Current pooling status

Executive
Line http: // localhost: 8080/proxool-test/admin (proxool-test is your application name)
If there is no pool status, you will only see the words pools, so you should first execute
Http: // localhost: 8080/proxool-test/test. jsp
Connection Pooling status.

Pools

> Test-> JDBC: mysql: // www: 3306/test

DefintitionFor test

URL JDBC: mysql: // localhost: 3306/test
Driver Org. gjt. Mm. MySQL. Driver
Connections 0 (min), 15 (max)
Prototyping Off
Connection lifetime 11:00:00
Maximum active time 07:05:00
House keeping sleep time 30 s
House keeping test SQL Off
Fatal SQL exceptions Off
Statistics Off

Snapshot21:12:53

Start date 01 -?? -21:12:30 2003
Connections 1 (active), 0 (available), 15 (max)
   
Served 1
refused 0
Details
# Born Last
Start
Lap
MS)
Thread
1 21:12:31 21:12:31 22432 Thread-15
Less information

Proxool 0.7.2 (29-apr-2003 00:33)

Section 05Use properties or XML to set the db url and driver

The xml configuration file can be used inProgramUse jaxpconfigurator. Configure ("proxool. xml", false). The configuration file is set as follows:

 
WEB-INF/proxool. xml<? XML version = "1.0" encoding = "ISO-8859-1"?> <! -- The proxool configuration can be embedded within your own application's. anything outside the "proxool" tag is ignored. --> <something-else-entirely> <proxool> <alias> XML-test </alias> <driver-URL> JDBC: mysql: // localhost: 3306/test </driver-URL> <driver-class> Org. gjt. mm. mySQL. driver </driver-class> <driver-Properties> <property name = "user" value = "root"/> <property name = "password" value = "password"/> </driver-Properties> <maximum-connection-count> 10 </maximum-connection-count> 

You can also set properties in the program propertyconfigurator. Configure ("proxool. properties ");

 
WEB-INF/proxool. PropertiesJdbc-0.proxool.alias = property-testjdbc-0.proxool.driver-url = JDBC: mysql: // localhost: 3306/testjdbc-0.proxool.driver-class = org. gjt. Mm. MySQL. Driverjdbc-0.user = rootjdbc-0.password = passwordjdbc-0.proxool.maximum-connection-count = 10jdbc-0.proxool.house-keeping-test-sql = select current_date

If you use it on the web, you can set the servletconfigurator servlet to register it in Web. xml.

  
    
    
    
    
      proxool 
     
     
     
       servletconfigurator 
      
     
       Org. logicalcobwebs. proxool. configuration. servletconfigurator 
      
      
      
        xmlfile 
       
      
        WEB-INF/proxool. XML 
       
      
     
       1 
      
     
    
      admin 
     
    
      Org. logicalcobwebs. proxool. admin. servlet. adminservlet 
      
     
     
       admin 
      
     
      /admin 
      
     
     

In the program, you only need to use the alias to call the connection in the connection pool.

 
<% @ Page import = "Java. SQL. *; "%> <% connection = NULL; try {class. forname ("org. logicalcobwebs. proxool. proxooldriver "); connection = drivermanager. getconnection ("proxool. XML-test ");} catch (exception e) {out. println (E);} Out. println ("OK"); %>

Section 06Use connection. Close () to close the connection

To
I did not write close for the example above. I hope you will remember to use close () to close the connection after the connection is completed
Pool to avoid java. SQL. sqlexception:
Org. logicalcobwebs. proxool. proxoolexception: connectioncount is 10.
Maximum connection count of 10 cannot be exceeded.

3.

Proxool-set parameters

Proxool provides many ways to set the correlated data. In this case, three methods can be introduced first. In addition, the method can be directly set in Web applications, this is explained in the next topic.
You can use Java. util. properties directly in a Java program. For example:

Class. Forname ("Org. logicalcobwebs. proxool. proxooldriver"); Properties info =NewProperties (); Info. setproperty ("Proxool. Maximum-connection-count","20"); Info. setproperty ("Proxool. House-keeping-test-SQL","Select current_date"); Info. setproperty ("User","Caterpillar"); Info. setproperty ("Password","123456"); Connection conn = drivermanager. getconnection ("Proxool. Example: COM. MySQL. JDBC. DRIVER: JDBC: mysql:// Localhost: 3306/Guestbook", Info );

Of course, this method is hard coding in the program. To change the data, you must modify the original data case and re-compile the program, we can also use XML protocol or protocol to design and use XML Protocol as follows:

Proxool. xml
 
<? XML version ="1.0"Encoding =ISO-8859-1"?> <Something-Else-Entirely> <proxool> <alias> example </alias> <driver-URL> JDBC: mysql:// Localhost: 3306/guestbook </driver-URL><Driver-class> com. MySQL. JDBC. Driver </driver-class> <driver-Properties> <property name ="User"Value ="Caterpillar"/> <Property name ="Password"Value ="123456"/> </Driver-Properties> <maximum-connection-count> 10 </maximum-connection-count> Else-Entirely>

Here, example is a different name (alias) of the Failover pool. We use org. logicalcobwebs. proxool. configuration. jaxpconfigurator to retrieve XML. The following shows how to obtain the Failover handler for the failover:

 
Class. Forname ("Org. logicalcobwebs. proxool. proxooldriver"); Jaxpconfigurator. Configure ("Proxool. xml",False);//FalseIndicates non-certificate XMLConnection conn = drivermanager. getconnection ("Proxool. Example");

We can also configure the proxool using implicit parallelism. The internal content of the implicit parallelism is as follows:

Proxool. Properties
Jdbc-0.proxool.alias = examplejdbc-0.proxool.driver-url = JDBC: mysql:// Localhost: 3306/GuestbookJdbc-0.proxool.driver-class = com. MySQL. JDBC. Driverjdbc-0.user = caterpillarjdbc-0.password = 123456jdbc-0.proxool.maximum-connection-count = 10jdbc-0.proxool.house-keeping-test-sql = select current_date

We use org. logicalcobwebs. proxool. configuration. propertyconfigurator to retrieve the implicit parser. The following shows how to obtain the progressive Parser:

 
Class. Forname ("Org. logicalcobwebs. proxool. proxooldriver"); Org. logicalcobwebs. proxool. configuration. propertyconfigurator. Configure ("Proxool. properties"); Connection conn = drivermanager. getconnection ("Proxool. Example");

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.