Connection Pooling...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Connection Pooling...

  1. #1
    Ellen Miles Guest

    Connection Pooling...


    Hi All,
    Some of my confusion is about how to do connection pooling with JSP and Tomcat.
    I have used connection pools with ATG Dynamo but I'm not sure how to proceed
    without a big application server to handle it? Can you shed some lights?

    Thanks
    Ellen

  2. #2
    n n Guest

    Re: Connection Pooling...


    You can use Datasources in JSP it self using JNDI
    "Ellen Miles" <csc015@yahoo.com> wrote:
    >
    >Hi All,
    >Some of my confusion is about how to do connection pooling with JSP and

    Tomcat.
    >I have used connection pools with ATG Dynamo but I'm not sure how to proceed
    >without a big application server to handle it? Can you shed some lights?
    >
    >Thanks
    >Ellen



  3. #3
    Kingshuk Guest

    Re: Connection Pooling...


    >>Hi All,
    >>Some of my confusion is about how to do connection pooling with JSP and

    >Tomcat.
    >>I have used connection pools with ATG Dynamo but I'm not sure how to proceed
    >>without a big application server to handle it? Can you shed some lights?
    >>


    Since you do not have an application server , you
    will have to build your own connection pool that maintains a
    number of javax.sql.Connection objects.

    One way of doing this will be to have a singleton connection
    pool object which will have a getConnection and returnConnection method.
    Clients will do this :

    java.sql.Connection con = ConnectionPool.getInstance().getConnection() ;

    //Do something with the connection
    //

    //Now return it back
    ConnectionPool.getInstance().returnConnection( con ) ;


    The ConnectionPool object will read from a config file
    maxConnection and minConnection property to figure out how many
    connections to start with in the pool and whats the maximum
    size of the pool.
    And once you reach the max size you refuse to dole out a connection.
    The pool itself may be built using a hashtable.
    The key for the hashtable is the hash of the Connection object
    that you create. And the key will point to an object that stores
    the actual connection object and a boolean flag indicating whether the connection
    is being used by someone or not.

    On invocation of getConnection you scan through the hash table
    until you find a connection that is free. Set the flag to busy
    and return the connection.

    Once someone calls a returnConnection , get the hash of the Connection object,
    find the entry in the hashtable , set the
    flag to free and return.

    Of course there are whole lot of error condition checks/performance related
    algos here and multithreaded issues.

    Later you can add a thread in the background that checks for
    stale connection in your pool periodically and/OR timout for
    a connection(For example you give up on a hash table entry because a rogue
    client has not returned your connection
    within a prespecified amount of time).
    You can also decide to recycle your connection pool after a
    certain amount of time automatically.

    Hope this helps.
    Kingshuk



  4. #4
    bharat nagwani Guest

    Re: Connection Pooling...


    I use free connection pool from javaexchange.com

    "Ellen Miles" <csc015@yahoo.com> wrote:
    >
    >Hi All,
    >Some of my confusion is about how to do connection pooling with JSP and

    Tomcat.
    >I have used connection pools with ATG Dynamo but I'm not sure how to proceed
    >without a big application server to handle it? Can you shed some lights?
    >
    >Thanks
    >Ellen



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center