Preparing your application to use a connection pool

One of the first things we should learn in our life, after feeding, is using a connection pool. Especially when we are talking about databases. This is the case covered here.

Why? Because a connection opened with the database is costly in terms of resources used for it. Even worse, if we look closer at the process of opening a new connection, it uses a lot of CPU resources, for example.

Maybe it won't make much difference if you have two users using a database with a couple of registers in a few tables. But it can start causing trouble if you have dozens of users, or if the database is large and gives you sleepless nights when you have hundreds of users using a huge database.

Actually I, myself, saw in the early days of J2EE 1.3 (the year was 2002), a performance issue being solved by a connection pool in an application used by 20 people. There were a few users, but the database was really big and not so well-designed (the same for the application, I have to say).

But you may say: why does a connection pool help us with this? Because once it is configured, the server will open all the connections you asked for, when it is starting up, and will manage them for you.

The only thing you have to do is to ask: "Hey, server! Could you lend me a database connection, please?" and kindly give it back when you are done (which means as quickly as possible).

This recipe will show you how to do it.

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

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