What is connection pooling?

Showing Answers 1 - 15 of 15 Answers

James

  • Oct 30th, 2005
 

Many applications needs to connect to database for retreiving, upadating, deleting and inserting the data. For every activity with the database, there needs to be an connection established by the application server. If tens of thousands of connections are made to database server for every request, then it chokes-up the network and server hangs. To avoid, this, the Connection Pooling mechanism, provides way of storing established connections in the memory. This is nothing but, pool all the connections at one place. Every time a database conenction needs to be established, a request is made to pool or any object which holds all the connections to provide a connection. Once that particular database activity is completed, the connection is returned back to the pool. Many J2EE application servers, provide their own connection pooling mechanism.

FRANCIS

  • Nov 18th, 2005
 

Connection pooling is a collection of database connections that is maintained by memeory.that can be reused.once  an application has finished its physical connnection,the connection is recycled rathe than being destroyed.

with regards

Francis.a

  Was this answer useful?  Yes

parindia

  • Feb 24th, 2006
 

Connection Pool is nothingbut is getting a connection by using specified drivers and lot of resourses at working at a time. It will not close immediately because lot of resources working. examplethree java programs working in concurently so it is not good to disconnect the databasesteps involved to create:1) write public class for initilise purpose Connection Pool (ie) vector class2) write take a connection from pool to customer3) write a method which as take a connection and to vector4) house sweeping ie cleaning purpose.every client program should know how getting connection afte finishing it setback connection. when a client wants a connection pool to request to pool and make. then finished and return back to pool

  Was this answer useful?  Yes

parindia

  • Mar 12th, 2006
 

hi suresh this my code for connection pool

public class ConnectionPool {

    Vector connections = null;
    static ConnectionPool instance = null;
 public static final int MAX_CONNECTIONS = 10;

   public synchronized void removeAllConnections() {

  if (connections == null) {
                return;
        }

        try {
            int sz = connections.size();
            for (int i = 0; i < sz/2; i++) {
       Connection c = (Connection) connections.elementAt(i);

                c=null;
                connections.remove(i);
            }

            if (connections!=null && connections.size() > 0) {
    connections.removeAllElements();
   }
            connections = null;
        } catch (Exception e) {
            System.out.println("Error" + e);
  }
  instance =null;

    }

    public static synchronized ConnectionPool getInstance() {
        if (instance == null)
            instance = new ConnectionPool();

        return instance;
    }

    public synchronized void initialize() {


        if (connections == null) {

            try {
    Class.forName("com.mysql.jdbc.Driver");
                connections = new Vector();
                int count = 0;
                while (count < MAX_CONNECTIONS) {
                    Connection c = DriverManager.getConnection("jdbc:mysql://localhost/lara");
                    connections.addElement(c);
                    count++;
                }
    System.out.println("total connections created r:"+ count);
            } catch (Exception e) {
    System.out.println("initialise:Exception");
                e.printStackTrace();
                instance.removeAllConnections();

            }
        }
    }

    public synchronized Connection getConnection() {
  System.out.println("getConnection");
        Connection c = null;
        if (connections == null)
            return null;

        if (connections.size() > 0) {
            c = (Connection) connections.elementAt(0);
            connections.removeElementAt(0);
        }
        return c;
    }

    public synchronized void putConnection(Connection c) {

        if (c != null) {
            connections.addElement(c);
            notifyAll();
        }
    }
}

  Was this answer useful?  Yes

sbarik

  • May 12th, 2007
 

Ther's some problem in above code .
1.The constructor is missing
2.Initialize method has not been called from in any where in the code.

The pool which i will suggest is  as below.
1.define two variables MIN_CONNECTION(miimum no of connection tat sud be in the pool) and MAX_CONNECTION (max no pf coonections)

2. In the initialize method intialize the pool to have minimum no of connections as specified in the MIN_CONNECTION variable.

3.From the constuctor call the initialize()  method to have minimum no of connections in the connection poll when the instance gets created

4.There should be a getConnection(long timeout) method .Instead of directly returning null when a connection is not available we should wait sometime as specified  by timeout parameter to get a free connection .If still its not available return null. 

Let me know if u have any question...
 

  Was this answer useful?  Yes

Hi Its gud code

I tried this and made connection pool but when i tried to call getConnection method of this class its giving me null value.
can u tell me please how can i get the connection from this pool.

  Was this answer useful?  Yes

In the previous days database connections are maintained by database only for example oracle database is having 10 database connections are there.Consider at the same time 10 clients are asked for a particular page then total 10 connecions are assigned to these 10 clients after some time 11th client has entered then there is no connection to give to the new client he has to wait until any one of the 10 clients has subbmited their connection to the database. Here the problem is if any one of the client has forget to close his connecion then his connection is not at all closed so it becomes waste all things are maintained by database only which makes more burden on the database server.

Inorder to remove the burden on the database server we introduced connection pooling concept which is maintained by application servers not by the database server. So connection closing and connection giving to the clients every thing is maintained by the applicaiton servers only. First application servers take some set of connections from the database and the application servers are going to maintain all the connections. 

  Was this answer useful?  Yes

CareerBaba.in

  • May 7th, 2014
 

Opening database connection is a time consuming operation. Connection pooling increases the performance of the applications by reusing the active database connections instead of create new connection for every request.

Connection pooling Behavior is controlled by the connection string parameters. Following the the 4 parameters that control most of the connection pooling behavior.

* Connect Timeout
* Max Pool Size
* Min Pool Size
* Pooling

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions