WebLogic: DataSource on Clusters

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.


Comments:

I understand as the datasource is targetted to a cluster with three servers we should have 50 * 3 = 150 connections.

However, can you help me explain in the client code as I am getting only 50 connections that too in the server ip port i specified in my code.

How can I specify the cluster. Can you give me the syntax ?

public class ConnectionTest
{
public final static String JNDI_FACTORY = "weblogic.jndi.WLInitialContextFactory";
private static String serverUrl ="t3://serveroneip:8001";

public static void main(String ar[])throws Exception
{
InitialContext ic=null;
try{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, JNDI_FACTORY);
env.put(Context.PROVIDER_URL, serverUrl);
ic = new InitialContext(env);
}
catch(Exception e){
System.out.println("\n\n\t Unable To Get The InitialContext => "+e);
}
Connection con[]=new Connection[100];
try{

for(int i=0;i<100;i++)
{
DataSource ds=(DataSource)ic.lookup("myDataSource"); //Enter your DataSource or MultidataSource JNDI name Here
con[i]=ds.getConnection();
System.out.println("\n\n\t GOT CONNECTION con["+i+"]: "+con[i]);
Thread.sleep(1000);
}

Posted by guest on December 13, 2012 at 08:16 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

Oracle ECEMEA Partner Hubs Migration Center Team

We share our skills to maximize your revenue!
Our dedicated team of consultants can rapidly and successfully assist you to adopt and implement the latest of Oracle Technology in your solutions.

Stay Connected
partner.imc
@
beehiveonline.oracle-DOT-com
Google+

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
2
3
4
5
6
9
10
11
12
13
14
16
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today