Reprinted: https: //www.jianshu.com/p/381c86bdbff6
I looked at the druid and dbcp2 original code and found that they all have their own way of connecting storage.
druid :
private volatile DruidConnectionHolder[] connections;
dbcp2
private final LinkedBlockingDeque<PooledObject<T>> idleObjects =
new LinkedBlockingDeque<PooledObject<T>>();
To their own understanding wrote a simple connection pool
- LinkedBlockingQueue management using a database connection
- Implement the interface javax.sql.DataSource
- Using the configuration design pattern
- Get driven by reflection technique
- 6 MYSQL5 compatible with the drive
- It supports the configuration of the connection pool resource depletion treatment strategy
- Idle connections unimplemented control
Core Source
-
Initialize the connection pool
-
Get connected
-
Connection release
-
Use connection pooling