GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE
Go To First  |  Previous Question  |  Next Question 
 J2EE  |  Question 5 of 104    Print  
What is connection pooling?

  
Total Answers and Comments: 7 Last Update: September 12, 2007     Asked by: koteswararao 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
October 30, 2005 10:25:28   
James        

RE: what is connection pooling?
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.
 
Is this answer useful? Yes | No
November 18, 2005 01:30:30   
FRANCIS        

RE: what is connection pooling?

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


 
Is this answer useful? Yes | No
February 24, 2006 13:01:51   
parindia Member Since: October 2005   Contribution: 6    

RE: what is connection pooling?
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
 
Is this answer useful? Yes | No
March 11, 2006 22:46:38   
nuthana Member Since: February 2006   Contribution: 2    

How to write the connection pooling using vector,arraylist un java?

Actually i want to know about how can we write connection pooling using Vector ArrayList classes in java.

will u please explain with sample code.

Regards

Suresh


 
Is this answer useful? Yes | No
March 12, 2006 14:42:31   
parindia Member Since: October 2005   Contribution: 6    

RE: what is connection pooling?

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();
}
}
}


 
Is this answer useful? Yes | No
May 12, 2007 14:19:58   
sbarik Member Since: January 2006   Contribution: 27    

RE: what is connection pooling?

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...


 
Is this answer useful? Yes | No
September 12, 2007 02:25:36   
gptnitesh Member Since: September 2007   Contribution: 11    

RE: What is connection pooling?
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.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2010 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape