Tuesday, March 15, 2011

Understanding Data Sources and Connection Pool in Weblogic


Terms like datasources and connection pools are very familiar to weblogic developers and admins. Most of the times developer ask for datasource creation on weblogic servers. Developers  or admins who have worked on Oracle Application server also will be familiar with these terms. Newbies often get confused about these and the difference between the two.


In simple terms Applications deployed on weblogic servers(managed servers) use the datasources( created on Weblogic server level) to connect to the databases.


Though the connection can be made at the deployed code level(JDBC connect strings) Data sources and their connection pools provide connection management processes that help keep your system running and performant.You can set options in the data source to suit your applications and your environment. 


I explain the concepts in more details below:






Data Sources


In WebLogic Server, you configure database connectivity by adding data sources to your WebLogic domain. WebLogic JDBC data sources provide database access and database connection management. Each data source contains a pool of database connections that are created when the data source is created and at server startup. Applications reserve a database connection from the data source by looking up the data source on the JNDI tree or in the local application context and then calling getConnection(). When finished with the connection, the application should call connection.close() as early as possible, which returns the database connection to the pool for other applications to use.


Connection Pool


Each JDBC data source has a pool of JDBC connections that are created when the data source is deployed or at server startup. Applications use a connection from the pool then return it when finished using the connection. Connection pooling enhances performance of the application server or deployed application response time by eliminating the costly task of creating database connections for the application.


Hope the above post helps. In future posts I would write on how to create connection pools in Weblogic and more importantly tuning them.

2 comments:

  1. Hello Sanjay,
    We are facing a problem while using Weblogic data source with hibernate .
    So we have a jpa.properties which have an entry to use weblogic data source

    **********
    hibernate.connection.datasource=java/MyDS
    hibernate.jndi.url=t3://localhost:7001
    hibernate.jndi.class=weblogic.jndi.WLInitialContextFactory
    **********

    I have a standalone java program where millions of messages are coming and there are multiple java threads (max 50 at a time) running , using the data base connection to persist the data.

    Now the issue is what ever size I define for connection pool for this data source , I end up consuming all in a fraction of a second . I defined 250, 500 size. but still i get exception saying "Unable to get connection, increase size of data source".

    Can you point me to some details documentation which talks about how to configure an efficient data source in Weblogic? And use it with an external application (as in my case).

    I am using Oracle weblogic server 11gR1 patchset 3.

    ReplyDelete
  2. DreamHost is ultimately one of the best web-hosting provider for any hosting plans you might require.

    ReplyDelete