WebLogic: DataSource on Clusters
By Gokhan Gungor on May 03, 2012
Almost all enterprise java applications require a database resource which is a very expensive and limited resource. The simplest way of using this resource requires performing the following steps; loading JDBC driver, obtaining a connection from the database manager, performing database operation, closing the connection. This method is inefficient and obtaining a database connection that way is an expensive operation because of the overhead involved in the process. It is a better approach to create the pool of database connections and reuse them for each incoming request or method call. That way we retrieve a connection from the pool when necessary and return it back to make it available for other programs.
In WebLogic Server we can use jdbc data sources to create database pools, connect databases and manage database access. We can then target and deploy these data sources to servers or clusters in WebLogic domain. We can create a data source with WebLogic admin console (DOMAIN>Services>Data Sources.) Data source created by administration console is considered system modules. System modules are globally available for targeting to servers and clusters configured in the domain, and therefore are available to all applications deployed on the same targets.
When a data source is deployed on a server, WebLogic Server creates an instance of the data source on the server along with the pool of database connections in the data source. When you deploy a data source to a cluster, WebLogic Server creates an instance of the data source on each server in the cluster. That means if you have a cluster with 3 managed servers and if you create a data source with initial capacity of 20 and target this data source to all the servers in the cluster, you will be creating total of 60 initial connections on your database.
Targeting the data source to the cluster will NOT enable failover of connections, but it will ease the process of reconnecting when a connection fails. If you want to failover your data source then you should check Multi Data Source feature WebLogic Server provides. However please keep in mind that JDBC is a highly stateful client-DBMS protocol, in which the DBMS connection and transactional state are tied directly to the socket between the DBMS process and the client (driver). For this reason, failover of a connection while it is in use is not supported.