A connection pool is a cache of database connection objects. The objects represent physical database connections that can be used by an application to connect to a database. At run time, the application requests a connection from the pool. If the pool contains a connection that can satisfy the request, it returns the connection to the application. If no connections are found, a new connection is created and returned to the application. The application uses the connection to perform some work on the database and then returns the object back to the pool. The connection is then available for the next connection request.
Universal Connection Pool (UCP) for JDBC provides a connection pool implementation for caching JDBC connections. Java applications that are database-intensive use the connection pool to improve performance and better utilize system resources. A UCP JDBC connection pool can use any JDBC driver to create physical connections that are then maintained by the pool. The pool can be configured and provides a full set of properties that are used to optimize pool behavior based on the performance and availability requirements of an application. For more advanced applications, UCP for JDBC provides a pool manager that can be used to manage a pool instance.
This chapter describes how to create a Universal Connection Pool. This chapter has the following sections:
To create a Universal Connection Pool, first you must set JDeveloper project properties by performing the following steps:
From the Application menu, select Default Project Properties.
Click Libraries and Classpath on the left panel of the Default Project Properties screen.
Click Add JAR/ Directory on the right pane of the Default Project Properties screen.
The Add Archive or Directory screen is displayed.
The following example is a stock ticker application that uses the Universal Connection Pool to retrieve stock price information from the database. Using this example, you can view the Universal Connection Pool properties, change the properties at run time without shutting down the pool instance, view Universal Connection Statistics and so on. Perform the following steps to run the example:
Click New Application in the Application Navigator panel.
StockTickerApp as the Application Name in the Name Your Application screen and click Next.
StockTickerProj as the Project Name in the Name Your Project screen and click Finish.
Click Open from File menu.
DbConfig.properties files and click Open.
DbConfig.properties file, verify the information about the user name, the password, and the URL of your Oracle database.
UCPDemo.java tab in the code editor and select Add to StockTickerProj.jpr.
Retain the default value for the content path in the Add to Project Content screen and click OK.
UCPDemo.java file in the Application Navigator window and click Make.
Select Choose Active Run Configuration from the Run menu and then select Manage Run Configurations.
Click Edit in the Project Properties screen for the
The Edit Run Configuration screen is displayed.
8067 or any free port on your system in the Program Arguments field and click OK.
Click OK to exit the Project Properties screen.
UCPDemo.java file in the Application Navigator window and click Run.
When you run the application, initially it will spend a few seconds to store the stock price data into the database. So, wait until the message
"...ready to go!" is printed out on the screen as shown in Figure 8-11.
After the message is displayed, the UCP demo server is up and running and you can use it by using the following steps:
Enter the following URL in the address bar of your browser:
The Universal Connection Pool Demo page is displayed.
Click the links below the Try the Demo: section to retrieve stock price information from the database.
Click Show UCP Properties to see the UCP properties:
Click Get Stock Price from Database to run the stock ticker:
Click Show UCP Statistics to see the UCP statistics:
Click Dynamically Reconfigure UCP Properties to update the UCP properties:
Note:You can change the UCP properties in the browser by clicking the Dynamically Reconfigure UCP Properties link. However, if you try to set a property that is not relevant for a single instance Database, then an exception may be thrown.
Click Run Massive Website Client Access Simulation to simulate many stock ticker clients using the service simultaneously:
This page provides the following fields:
||Specifies the URL of ticker web service|
||Specifies the number of concurrent threads to run|
||Specifies number of ticker requests per thread to run|