Pool resources - database connection pool to achieve simple version -JAVA

 

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

  1. Initialize the connection pool


     

    Initialize the connection pool .png
  2. Get connected


     

     

    Get connected .png
  3. Connection release


     

     

    Release the connection .png
  4. Use connection pooling


     

     

    Use .png

github source address

ClawDataSource

Guess you like

Origin www.cnblogs.com/shoshana-kong/p/11249162.html