8 Creating a Universal Connection Pool

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:

8.1 Setting JDeveloper Project Properties

To create a Universal Connection Pool, first you must set JDeveloper project properties by performing the following steps:

  1. From the Application menu, select Default Project Properties.

    Figure 8-1 Setting the Default Project Properties

    Description of Figure 8-1 follows
    Description of "Figure 8-1 Setting the Default Project Properties"

  2. Click Libraries and Classpath on the left panel of the Default Project Properties screen.

    Figure 8-2 Setting the Libraries and Classpath

    Description of Figure 8-2 follows
    Description of "Figure 8-2 Setting the Libraries and Classpath"

  3. Click Add JAR/ Directory on the right pane of the Default Project Properties screen.

    The Add Archive or Directory screen is displayed.

  4. Select ucp.jar file in the $ORACLE_HOME/ucp/lib folder and click Select.

    Figure 8-3 The Add Archive or Directory Screen

    This image illustrates how to add a jar to the classpath.
  5. Click OK.

8.2 Creating the Stock Ticker Application

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:

  1. Click New Application in the Application Navigator panel.

    Figure 8-4 The Application Navigator Panel Options

    This image illustrates how to create a new application.
  2. Enter StockTickerApp as the Application Name in the Name Your Application screen and click Next.

  3. Enter StockTickerProj as the Project Name in the Name Your Project screen and click Finish.

  4. Click Open from File menu.

  5. Select the UCPDemo.java, ClientSimulator.java, DBConfig.java, HttpServer.java, and DbConfig.properties files and click Open.

  6. In the DbConfig.properties file, verify the information about the user name, the password, and the URL of your Oracle database.

    Figure 8-5 The DbConfig.properties File in the Code Editor

    This image illustrates the content of the DBConfig file.
  7. Right-click the UCPDemo.java tab in the code editor and select Add to StockTickerProj.jpr.

    Figure 8-6 Adding a Source File to a Project

    This image illustrates how to add a file to a project.
  8. Retain the default value for the content path in the Add to Project Content screen and click OK.

    Figure 8-7 The Add to Project Content

    This image illustrates how to add a file to a project.
  9. Repeat steps 7 and 8 for ClientSimulator.java, DBConfig.java, HttpServer.java, and DbConfig.properties files to add them to the StockTickerProj project.

  10. Right-click the UCPDemo.java file in the Application Navigator window and click Make.

  11. Select Choose Active Run Configuration from the Run menu and then select Manage Run Configurations.

    Figure 8-8 The Run Menu Options

    Description of Figure 8-8 follows
    Description of "Figure 8-8 The Run Menu Options"

  12. Click Edit in the Project Properties screen for the StockTickerProj project.

    Figure 8-9 The Project Properties Screen for the StockTickerProj Project

    Description of Figure 8-9 follows
    Description of "Figure 8-9 The Project Properties Screen for the StockTickerProj Project"

    The Edit Run Configuration screen is displayed.

  13. Enter 8067 or any free port on your system in the Program Arguments field and click OK.

    Figure 8-10 The Edit Run Configuration Screen

    Description of Figure 8-10 follows
    Description of "Figure 8-10 The Edit Run Configuration Screen"

  14. Click OK to exit the Project Properties screen.

  15. Right-click the UCPDemo.java file in the Application Navigator window and click Run.

8.3 Observing the Output

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.

Figure 8-11 Output of the Stock Ticker Application in JDeveloper Log

This image shows the output of the stock sticker demo

After the message is displayed, the UCP demo server is up and running and you can use it by using the following steps:

  1. Enter the following URL in the address bar of your browser:

    http://localhost:8067

    The Universal Connection Pool Demo page is displayed.

    Figure 8-12 Retrieving Information from the Universal Connection Pool Using the Browser

    This image describes the UCP options on the browser
  2. 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:

    Figure 8-13 The UCP Properties page

    Description of Figure 8-13 follows
    Description of "Figure 8-13 The UCP Properties page"

    Click Get Stock Price from Database to run the stock ticker:

    Figure 8-14 The Stock Ticker Page on the Browser

    Description of Figure 8-14 follows
    Description of "Figure 8-14 The Stock Ticker Page on the Browser"

    Click Show UCP Statistics to see the UCP statistics:

    Figure 8-15 The UCP Statistics Page on the Browser

    Description of Figure 8-15 follows
    Description of "Figure 8-15 The UCP Statistics Page on the Browser"

    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.

    Figure 8-16 The UCP Properties Update Page on the Browser

    Description of Figure 8-16 follows
    Description of "Figure 8-16 The UCP Properties Update Page on the Browser"

    Click Run Massive Website Client Access Simulation to simulate many stock ticker clients using the service simultaneously:

    Figure 8-17 The Client Simulator Page on the Browser

    Description of Figure 8-17 follows
    Description of "Figure 8-17 The Client Simulator Page on the Browser"

    This page provides the following fields:

    Ticket server URL: specifies the URL of ticker web service

    Number of simulated users (threads) to run: specifies the number of concurrent threads to run

    Number of ticket requests per user: specifies number of ticker requests per thread to run