Connection pooling should be said to be an idea, a kind of rational use of resources. The connection pool resolves the following issues:
1. Java and database time-consuming issues when establishing a connection
2. Database connection establishment too much prone to crash problems
3. Issues that cannot be fully exploited for each connection
The connection pool is suitable for multi-threading and a large number of duplicate operations database projects. The idea of connection pooling is that when your program starts, a certain number of connections are first established, and the connection is placed in a data structure, just as the side is in a pool, when the first thread needs to access the database, a connection is taken from the pool, assigned to the thread, This thread accesses the database through this connection, and when it is finished, it does not close the connection, but instead puts it back into the pool. A connection is then taken out of the pool when the thread is needed. In general, how many connections in a pool can satisfy how many threads concurrently access the database. If you need too many connections at the same time, there is not enough connectivity in the connection pool to generate a new connection based on the policy. The general connection pool will have the upper limit, when the upper limit is no longer establish a new connection, mainly to prevent excessive connection caused by the machine resource exhaustion, if there is no connection in the connection pool, but still wired to wait for the connection to let these threads wait until other threads run out of connection and put back to the connection pool. The above is the basic idea of the connection pool, better connection pool good need to have other technology to ensure the stability and performance of the connection pool.
WebLogic Connection pool configuration, in your project need to use Jndi to get DataSource instances to access the database, there are many such articles online, you can find.
That's what I said. Connection pooling is commonly used for multiple-thread duplication of operational database projects, especially in B/s mode or C/s mode for multi-client database-based systems. So it's necessary to use a connection pool for either the Java EE or the J2SE as long as this condition is met.
The code is not given, this place can not be affixed to the net down to
When an application requests a connection, the connection pool assigns a connection to the application instead of re-establishing a connection, and when the application finishes using the connection, the connection is returned to the connection pool instead of being released directly.
How to implement a connection pool
Make sure you use the same connection string (the same as the connection pool) for each connection, and only the connection string will work when the connection pool is connected. If the connection string is not the same, the application does not use a connection pool but creates a new connection.
Advantages
The main advantage of using connection pooling is performance. The time it takes to create a new database connection depends largely on the speed of the network and the distance between the application and the database server (network), and this process is often a time-consuming process. With a database connection pool, the database connection request can be met directly through the connection pool without having to reconnect to the request and authenticate to the database server, saving time.
Disadvantages
There may be multiple connections in the database connection pool that are not being used to connect to the database (which means a waste of resources).
Tips and Hints
1. When you need a database connection, create a connection pool instead of building it in advance. Once you're done using the connection, close it immediately, and don't wait for the garbage collector to handle it.
2. Ensure that all user-defined transactions are closed before closing the database connection.
3. Do not close all connections in the database, at least one connection in the connection pool is guaranteed to be available. If memory and other resources are issues that you must first consider, you can close all connections and then create a connection pool when the next request arrives.
Connection Pooling FAQ
1. When do I create a connection pool?
Creates a connection pool when the first connection request arrives, and the connection pool's establishment is determined by the connection word Fu Shilai of the database connection. Each connection pool is associated with a different connection string. When a new connection request arrives, if the connection string is the same as the string used by the connection pool, a connection is taken from the connection pool, and if it is not the same, a new connection pool is created.
2. When do I close the connection pool?
Closes the connection pool when all connections in the connection pool have been closed.
3. What happens when a connection in the connection pool is exhausted and a new connection request arrives?
When a connection pool has reached its maximum number of connections, new connection requests are placed in the connection queue when a new connection request arrives. When a connection is released to the connection pool, the connection pool assigns the newly freed connection to the connection request that is queued in the queue. You can call close and Dispose to return the connection to the connection pool.
4. How should I allow connection pooling?
For. NET applications, the default is to allow connection pooling. (which means you don't have to do anything for this matter) of course, if you can add Pooling=true to the SqlConnection object's connection string, make sure your application allows connection pooling.
5. How do I disable connection pooling?
Ado. NET defaults to allow database connection pooling, if you want to disallow connection pooling, you can use the following methods:
1) When using the SqlConnection object, add the following to the connection string: Pooling=false;
2) When using the OleDbConnection object, add the following to the connection string: OLE DB services=-4;