Preparing your application to use a connection pool

One of the first things we should learn in our lives, after feeding, is how to use a connection pool – especially when we are talking about databases. That's the case here.

Why? Because a connection opened with a database is costly in terms of the resources used for it. If we look closely at the process of opening a new connection, we see that it uses a lot of CPU resources, for example.

Maybe it won't make much of a 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 went 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 starts up and will manage them for you.

The only thing you have to do is say, "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 this.

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

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