"From e-mentor Network " Java programmers are envious of Windows ADO, just need new Connection can directly from the database connection pool to return Connection. and ADO Connection is thread-safe, multiple threads can share a single Connection, so the ASP program generally puts getconnection in the Global.asa file and establishes the database connection when IIS starts. The connection and result of ADO are well buffered and easy to use. Learn about the still Silicon Valley JDBC video tutorial .
We can actually write a JDBC database connection pool ourselves.
The considerations for writing JDBC Connection pool are:
1. There is a simple function to get a Connection from the connection pool.
2. The close function must put connection back into the database connection pool.
3. When there is no idle connection in the database connection pool, the database connection pool must be able to automatically increase the number of connection.
4, when the number of connection in the database connection pool becomes very large in a particular time, but after a long time to use only a small part, should be able to automatically turn off the extra connection.
5. If possible, the debug information report should be provided without closing the new Connection.
If you want new Connection to be able to return Connection directly from the database connection pool, you can write (mediator pattern) (Chinese full-width spaces are used in the following code):
It's not that hard. However, this is not recommended, because Java Interface should be avoided as much as possible, and I will write another discussion about the drawbacks of Java Interface. Everyone is concerned about the connection Pool implementation method. Here is an implementation method.
Use:
After you run the test program, print the connection state in the JDBC database connection pool, and you are using the connection information that is not closed. e-Mentor Network has more knowledge of programming language Tutorials for you to learn.
Implementing a JDBC Database connection pool in Java