Article Title: Tomcat4 database connection pool configuration. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
This article describes how to configure the database connection pool in Tomcat4.0.6 and Tomcat4.1.18, and how to search for the JNDI of the connection pool by the program, and provides the relevant test code. At last, it points out the common problems and solutions in the configuration and application process.
1. Tomcat Introduction
Tomcat is a sub-project of Apache Jakarta and a JSP and Servlet Container recommended by Sun. As an excellent application server, Tomcat provides database connection pool, SSL, Proxy, and many other common component functions. Among them, the connection pool is a new feature in version 4.0 and is widely used.
Ii. Tomcat 4 connection pool
Tomcat4 development can be divided into two stages. 4.0.6 is the most recommended release version in the first stage. The built-in database connection pool is Tyrex 0.9.7.0 and Tyrex is developed by exolab.org. For more information, see www. exolab.org. Later, Tomcat developers reconstructed Tomcat on the basis of 4.0.x, And the reconstructed release version recommended 4.1.18. At this time, the built-in connection pool was changed to DBCP, which is also a subproject of Jakarta Commons.
Next, we will take 4.0.6 and 4.1.18 as examples to introduce the two connection pool configurations for Oracle8.1.7.
3. Configure Tyrex for Tomcat4.0.6
For convenience, set the connection pool to ROOT, the JNDI name to jdbc/OracleDB, the database server IP address to 192.168.0.50, And the SID to oradb. The configuration steps are as follows.
Step 1: Configure server. xml
In the server. xml file, find
Change it
DocBase = "ROOT" debug = "0">
Type = "javax. SQL. DataSource"/>
User
Holen
Password
Holen
DriverClassName
Oracle. jdbc. driver. OracleDriver
DriverName
Jdbc: oracle: thin :@ 192.168.0.50: 1521: oradb
Note: remove the ROOT Context from the comment and define the Resource item as follows:
Type = "javax. SQL. DataSource"/>
Resource (the DataSource object of the Connection Pool) has three attributes: name, auth, and type. The name is the name definition of JNDI, and this object can be found by the program through JNDI, the name is jdbc/OracleDB. The auth item is the management attribute of the connection pool. The Container value is the Container management item. The type item is the object type. The javax value is used here. SQL. dataSource, declared as a database connection pool. Tyrex can be used not only as a database connection pool, but also has many other functions. If you are interested, you can open the jar package of Tyrex to see or access www.exolab.org. I will not talk about it here.
In the following The domain content includes four parameters: user, password, driverClassName, and driverName, which are the user name, password, JDBC driver, and database address of the database in sequence.
The user name and password are prepared for accessing the database. The value here is holen.
DriverClassName is the JDBC driver name of the database. For example, the JDBC driver package of Oracle8.1.7 is named classes. jar, which is generally located in the ora81 \ jdbc \ libdirectory under the Oracle installation directory. The extension name is zip, and the classes.zip name is manually changed to classes. jar and put it under common/lib. Here, the value is oracle. jdbc. driver. OracleDriver, which is provided by classes. jar.
For other databases, such as MySql, The driverClassName is org. gjt. mm. mysql. Driver.
The last parameter is driverName, which is the address of the database. (To be precise, it should be called url, and it should be changed to url in 4.1.18)
Enter the Oracle access address here. If it is MySql, DB2, SQL Server, or other databases, enter the corresponding address.
Step 2: Copy the Oracle JDBC driver classes12.jar to common/lib in the Tomcat installation directory. The same applies to other databases. Place the corresponding JDBC driver package in common/lib, for example, MySql JDBC driver package mm. mysql-2.0.14.jar.
Now, the configuration is complete and the test code will be provided later.
Configure Tomcat4.1.18 DBCP
4. Configure Tomcat4.1.18 DBCP
The configuration method is slightly different from 4.0.6. The configuration procedure is as follows:
Note: The configuration file shows that the configuration of DBCP is similar to that of Tyrex, but the function is richer. The same is not much said, but it focuses on different places.
That is, the basic object factory. Here, the value is org. apache. commons. dbcp. basicperformancefactory, that is, the factory that comes with DBCP. You can also use something else.
Although DBCP is used as the connection pool in 4.1.18, Tyrex can still be used as the connection pool. At this time, Tyrex has been upgraded from 0.9.7.0 to 1.0, and JTA/JCA objects are supported, the object is still obtained through JNDI. For specific configuration methods, see the Tomcat documentation.
The url is the database access address, as mentioned before.
The following three parameters are related to the number of connections:
MaxActive
20
MaxIdle
10
MaxWait
-1
MaxActive is the maximum number of activated connections. The value is 20, indicating a maximum of 20 connections to the database.
MaxIdle is the maximum number of idle connections. The value is 10, indicating that 10 idle connections can be maintained even if no connection request is sent, and the connections are not cleared. The connections are always on standby. If you are interested in the object status, you can check the EJB information.
MaxWait is the maximum number of waiting seconds. Here, the value-1 indicates infinite waiting until the timeout period ends. It can also be set to 9000, indicating timeout after 9 seconds.
For some suggestions on maxActive and maxIdle, for enterprise-level applications, the values of the two are generally close or the same. The key is to analyze the application size.
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.