[ Team LiB ] Previous Section Next Section

Context

Connection initialization is notorious for being one of the slowest data access operations. Since connecting to a database is a prerequisite for any data access, it offers an opportunity to introduce significant bottlenecks to even the most straightforward applications. Simple standalone applications tend to initialize database connections when they begin and leave the connections open as long as they continue running.

Server and middle-tier programs like Java servlets and enterprise applications can also take this approach. However, applications in these environments usually need to service multiple concurrent users and sharing the same database connections is usually not feasible. One reason is that many threads contend for the same connection. This condition manifests as either non-threadsafe behavior that is difficult to debug or extensive blocking that noticeably reduces response time. You can alleviate this condition by creating a database connection for each active session. This strategy often results in many more active connections than an application actually needs at any given point in time because most of these connections sit idle while end-users peruse data that the application presents to them.

A prevalent and much more effective solution to this problem is a resource pool. A resource pool manages a set of active resources that is recycled for repeated use. A single application or server session no longer needs to monopolize a particular database connection to avoid connection initialization overhead. Instead, it checks out a connection from a global pool whenever it needs to access the database. As long as the application or session code is using the connection, no other application or session is able to access it. When it is done with its database work, the application or session code checks the connection back into the pool for others to use.

If a client requests a resource from the pool and none are available, it is the resource pool's responsibility to create a new resource. This enables the application to easily and efficiently gain access to a new resource without any concern for whether the resource is recycled or brand new.

    [ Team LiB ] Previous Section Next Section