Java Reference
In-Depth Information
After our trip to the Gunnison Gorge, I decided that I liked boating much more
than I liked driving. Hiking and driving took time and energy away from the
river. Once I reached the river, I vowed to try to find runs in the future with less
driving and hiking and more river time. We should be so diligent as program-
mers and attempt to minimize the setup time in favor of providing service. Java
has a connection framework that allows us to do exactly that by offering pooling
and other services. Connection pooling can mean a dramatic difference in per-
formance: Making any connection is an expensive process, and a pool of con-
nections reduces the setup costs by allowing you to reuse a connection.
How much of the total transaction cost might the connection represent? I
ran a test twice that summed up all the numbers in a database column. I did
this calculation 1,000 consecutive times. With the first test, I reconnected
each time I computed the sum. With the second test, I pooled connections.
The second test took less than half the time that the first example did, as
shown in figure 7.2.
Figure 7.3 offers another view of the savings. Here we see the database-
related costs of a servlet. We have to process a connection before we can pro-
ceed with the real work, and then we close the connection. If we were to use
connection pooling, after we prime the connection pool all of the work
involved in connecting to a database and closing that connection becomes
unnecessary. In figure 7.3, the black boxes represent redundant work. For the
normal case, we have a penalty that consists of a fixed cost per open connec-
tion (c1) and a cost for the connection close (c2). This penalty will be paid for
Figure 7.2
My program computed the total of a database column 1,000
times. The first column shows the results without connection
pooling; the second column shows the impact of sharing the
Database test without
connection pooling
Database test with
connection pooling
Search WWH ::

Custom Search