Databases Reference
In-Depth Information
long stopTimeMulti = System.currentTimeMillis();
System.out.println(String.format(
"Execution with single connection %dms.\n
Execution with multiple connections %dms.",
(stopTimeSingle - startTime),
(stopTimeMulti - stopTimeSingle)));
}
}
4.
Open a terminal and make chapter02 the current directory.
5.
Build the program by using the following command:
javac ConnectionManagement.java
6.
Open another terminal and make OraclePerformanceTuningCookbook , the
current directory. Run the program from the command line:
java chapter02.ConnectionManagement
7.
The output will be as follows:
Matthew Weiss
Jennifer Whalen
Eleni Zlotkey
Execution with single connection 2863ms.
Execution with multiple connections 4176ms.
How it works...
This simple example consists of two methods, singleConnection() and
multipleConnection() , which reads the names of all the employees in the HR schema
a hundred times.
The difference between the two procedures is in the way the connection to the database
is made. In singleConnection() , the connection is opened one time and closed after
100 executions. In multipleConnection() , for each iteration we open and close the
connection to the database. The only difference in the code is the position of the for loops,
as highlighted in the source code in step 3.
As we can easily see in the execution time presented in the output, the singleConnection()
procedure is approximately 30 percent faster than the multipleConnection() . Increasing
the number of iterations leads to a greater difference, and we consume more resources during
the log on and log off processes than while executing the SQL statements.
 
Search WWH ::




Custom Search