Database connection pool overview: Database connection is a key limited expensive resource, which is particularly highlighted in multi-user web applications. The management of database connections can significantly affect the scalability and robustness of the entire application, affecting the performance indicators of the program. The database connection pool is proposed for this issue. The database connection pool is responsible for assigning, managing, and releasing the database connection, which allows the application to reuse an existing database connection, and then re-establish a database connection to the idle time exceeding the maximum idle time to avoid because there is no release database connection. Indicated database connections. This technology can significantly improve the performance of database operations. Database connection pool When you initialize a certain number of database connections to the connection pool, the number of these database connections is set by the minimum database connection. Whether these database connections are used, the connection pool will always guarantee that there are at least so many connections. The maximum number of database connections for the connection pool limits the maximum number of connections that can be occupied. When the application of the application exceeds the maximum number of connections to the connection pool, these requests will be added to the waiting queue. The minimum connection of the database connection pool and the maximum number of connections are set to take into account the following factors: 1) The minimum connection is the database connection that the connection pool has always been maintained, so if the application is not used in the database connection, will There is a lot of database connection resources; 2) The maximum number of connections is the maximum number of connections for the connection pool. If the database connection request exceeds this, the rear database connection request will be added to the waiting queue, which will affect Database operation. 3) If the minimum number of connections is too large to the maximum number of connections, the first connection request will be profitable, and then the connection request for the minimum connection number is equivalent to establishing a new database connection. However, these database connections larger than the minimum connection number will not be released immediately, which will be released in the connection pool to be reused or idle.
Putting the above is: Adopting the connection pool is to reduce the overhead of the system to establish a data connection each time, while reaching a multiplexing, the cost of doing the connection between the system, reserved a part of the connection ( In fact, the concept of global variables is similar to the concept of global variables. When the request is made, all connections are extracted from here rather than to establish a connection. Process: Connection -> If there is connection -> Judgment whether the thread is less than the maximum junction ---> Yes ---> Create a new connection thread - -> is not ---> Waiting for a while --- > Return to the judgment ---> Retry exceeds the limit ---> Exit or report an error --------------------------------------------- --------------------------------------------------------------------------------------- ----- Reprinted from: BLOG of Func Real
This guide will explain how to configure the database connection pool in Tomcat installed. And the configuration method of this guide will not be handmade any .xml file, after all, is not a standard method, I am very referred to.
First install Tomcat, I believe that your Tomcat is not low, and the database connection pool is not supported.
There are many people ignoring the completion of the account password, and I don't know where to use it. In fact, this is the account password used to manage the Tomcat background. Maybe many people are depressed in Tomcat, there is no friendly interface to set it, wait for you to tell you.
After loading Tomcat, start Tomcat. Enter: http: // localhost: 8080 / Enter, you should see the welcome interface of Tomcat. This guide is not for Tomcat, please find yourself for other details. Now enter: http:// localhost: 8080 / admin Enter, you should be able to see his login interface. If you just have an engineering name called admin, then remove it, you should be able to delete it together even if you have a Work file in the Tomcat root directory, it should be reinstalled. Fill in your account password, log in. Don't say that you are not just being installed, I have long forgot the account password. The easiest way to reinstall. If you have turned out Tomcat, then you must be reinable, there is a way, find the Tomcat root directory /conf/tomcat-users.xml. Open, there is a line looks like this
, You should know how to take a moment, Funcreal is an account, 123456 is a password. Please don't copy my account password, otherwise it will be joke! Log in to Tomcat's background, open TomcatService-> service-> host-> You want to configure the connection pool -> Resources-> Data Source. Ok, if there is no accident, you should see the friendly interface that configures the connection pool on the right. Select from the drop-down list: CREATE New Data Source. Open a new database connection pool configuration page. JNDI Name: JDBC / MSSQL (MSSQL is yourself, as for "JDBC /" in front, there is no research, Data Source URL is the connection string, JDBC Driver Class is driver, account password is your own database The account password, the rest is default. The last item can not be filled. Finally, Save-> Commit Changes. Everything is so simple. Moreover, you will look at the other information on your hand, and our server.xml file is very clean, there is no information to modify what your mess! The test file is as follows:
<% @ page contenttype = "text / html; charset = GBK"%>
<% @ page contenttype = "text / html; charset = GBK"%>
<% @ page import = "java.sql. *"%> <% @ page import = "javax.sql. *"%> <% @ page import = "javax.naming. *"%>
Head> <% out.print ("Hellou"); DataSource DS = NULL; try {INIALCONText CTX = new initialcontext (); DS = (Datasource) CTX.lookup ("Java: Comp / ENV / JDBC / MSSQL "); connection conn = ds.getConnection (); statement stmt = conn.createStatement (); string strsql =" select * from orderrs "; // Modify this statement. ResultSet RS = Stmt.executeQuery (strsql); while (rs.next ()) {Out.print (rs.getstring (1)); out.print (rs.getstring (3));}} catch (Exception EX) {EX.PrintStackTrace ();}%> body> html> ps: This is determined based on the specific database and driver. I am this: Data Source URL: JDBC: Microsoft: SQLServer: //172.168.0.66: //172.168.0.66: //172.168.0.66: //172.168.0.66: //172.168.0.66: //172.168.0.66: //172.168.0.66: //172.168.0.66: 1433; DatabaseName = TEST 72.168.0.66 changed to your IP address, 1433 can not change, DatabaseName replacement with your JDBC Driver Class : com.microsoft.jdbc.sqlserver.sqlserdriver You first want to ensure that this package is included in your project.