Connection management

Modern applications rarely create a JDBC connection directly. More often, connection pools are used. The reason behind this is pretty simple—establishing a new connection is costly. Consequently, it is wise to have a cache of connections managed in the way that allows reuse. The cost of creating a connection may come from two areas. First of all, the connection initiation process may require client authentication and authorization, and this takes up precious time. Secondly, a new connection may cost a database a fortune. For example, PostgreSQL creates a whole new process (not a thread!) whenever a new connection is established, which itself may take hundreds of milliseconds on a powerful Linux machine. At the time of writing, the most commonly-used connection pools for the Java platform are Apache Commons DBCP2, C3P0, Tomcat JDBC, and HikariCP. HikariCP is considered to be the fastest connection pool in the Java world.

Note that even though connection pooling is widely used for JDBC connectivity, it is not an inherent part of database communication. For example, the Oracle database driver allows connection multiplexing, which allows us to funnel multiple logical connections through a single network connection. Of course, such support is enabled not only by the driver but by the wire protocol and the database implementation itself.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.154.64