| | | | | | | | | | | | | | Article Summary
Title: | | Recommended JDBC Connection Pool | Description: | The recommended JDBC connection pool manager. | Key Words: | recommended, jdbc, sql, connection, pool, manager | Type: | FAQs | Category: | Java Virtual Machines | Last Updated: | 2004-01-08 04:58:39 |
| | | | |
| | | | Recommended JDBC Connection Pool
There are dozens of options for JDBC connection pooling available. Which do you recommend?
With literally dozens of connection pool managers available, you might be surprised that we recommend one we have developed in-house. We recommend using the com.aoindustries.sql.AOConnectionPool connection pool.
Strengths of our pooling code include:
- Ease of Use
- Reliability
- Efficiency
- Statistics
Ease of Use
Using it only requires four simple steps.
-
Instantiate the connection pool
public static final AOConnectionPool pool=new AOConnectionPool(
driver,
jdbcUrl,
username,
password,
connections // 16 to 64 recommended
);
-
Obtain a connection
Connection conn=pool.getConnection();
-
Use the connection.
-
Release the connection
pool.releaseConnection(conn);
The overall code looks as follows:
import com.aoindustries.sql.*;
public static final AOConnectionPool pool=new AOConnectionPool(...);
public void method() throws SQLException {
Connection conn=pool.getConnection();
try {
// Use the Connection
} finally {
pool.releaseConnection(conn);
}
}
Reliability
The pooling code keeps track of threads and connections. It writes a warning to System.err when a thread allocates more than one connection, helping to isolate potential deadlocks. It also will not allow a thread to allocate more than half of the available connections, making deadlock less likely when there is a bug in the calling code.
Efficiency
The performance of the pooling code affects several aspects of the servers
-
Allocation and Deallocation Speed
The AOServ System is built on top of a PostgreSQL database using the AOConnectionPool code. This system currently processes over 15 million transactions per day. The pooling code has been optimized during the development of the AOServ automation system.
-
Java VM Resources
The connection pool dynamically allocates additional connections as needed and automatically closes idle connections. This keeps the number of active connections at a minimum, resulting in minimal heap allocation while not interfering with performance.
-
Server Scalability
Because the pool maintains a minimum number of connections, the backend systems, such as InterBase, MySQL, and PostgreSQL, run as efficiently as possible. On database systems such as InterBase and PostgreSQL, where a separate process handles each separate connection, this can lead to hundreds of megabytes of RAM saved.
In addition to RAM concerns, database systems have a finite number of connections they may concurrently handle. By allocating only what is needed, and scaling on demand, the pooling code allows multiple sites to work together well in a shared environment. This is particularly important on virtual servers where hundreds of sites might use the same database server.
Statistics
The pooling code automatically maintains useful and complete statistcs about connection use. These statistics aid in identifying bottlenecks in application code, server software, and server hardware.
How to Obtain the Code
The code is already in the CLASSPATH of all standard Tomcat and JBoss Java VMs. The JAR file is installed on every server under /usr/aoserv/lib/aocode-public.jar
You may also Download the aocode-public Binary and Source JARs.
You may also View the JavaDocs online.
| | | | |
| | | | | Copyright © 2000-2024 AO Industries, Inc. |
|