This is an excerpt from the bestselling book
Oracle Grid & Real Application Clusters. To get immediate
access to the code depot of working RAC scripts, buy it
directly from the publisher and save more than 30%.
WebLogic is a popular java
application server that codes and deploys web applications. WebLogic
supports connectivity to the Oracle database through JDBC drivers.
Code that opens a connection to a database can be inserted into web
pages or applications in the presentation or business layer. Thick
clients, such as standalone Java applications, can connect to remote
databases with RMI. Thin clients can embed database connection code
in servlets and JSP tags. Both EJB session beans and entity beans
can also use JDBC to connect to the Oracle database.
WebLogic has an advanced feature
called connection pooling that opens a specified number of
connections upon startup.
Connecting to a database using a
WebLogic Server in a two-tier configuration involves creating a
java.util.Properties object describing the connection. This object
contains name-value pairs containing information such as user name,
password, database name, server name, and port number.
For example:
Properties
props = new Properties();
props.put("user", "appowner");
props.put("password", "f514");
props.put("server", "ault1");
The server name, ault1 in the
preceding example, refers to an entry in the tnsnames.ora file,
which is located in the Oracle client installation. The server name
defines host names and other information about an Oracle database
instance. Once the tnsnames.ora entry is in use, the TAF facility
suitable for the Oracle RAC database can be used.
A WebLogic connection pool
consists of a group of JDBC connections that are created when the
connection pool is registered. This is done either by starting up
the WebLogic Server or by assigning the connection pool to a target
server or cluster. Connection pools use type 2 or type 4 JDBC
drivers to create physical database connections. An application
borrows a connection from the pool, uses it, and then returns it to
the pool by closing it.
MultiPool is a group of
connection pools. MultiPool helps in:
* Load Balancing: Pools in
WebLogic are accessed using a standard round-robin method. When
moving to a new connection, the WebLogic Server will select a
connection based on the next connection pool in the specified order.
* High Availability:
Connection pools are listed in the order that determines when
connection pool switching occurs. The WebLogic Server provisions
database connections from starting with the first connection pool on
the list. If for some reason that connection pool fails, it uses the
others specified in order.
As shown in Figure 11.6, there
are two connection pools. Each of the connection pools can be
configured to access a particular database instance of the Oracle
RAC.
Figure 11.6: WebLogic with JDBC
MultiPool Architecture
All of the connections in a
given connection pool are identical, but the connections within a
multipool can vary. These pools can be configured to access
different instances of the same database, as with the Oracle RAC. In
this way, the instances are effectively used and the database
resources are load balanced.
This feature is particularly
useful even if the JDBC thin driver is used. When a type 2 JDBC
driver or WebLogic jDriver for Oracle is used, the tnsnames.ora
connect string entry can be specified. The TNS entry can be based on
a TAF configuration so that load balancing and failover features can
be defined.