• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please tell me why really connection pool is needed

 
lakshmideepak katari
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends in the bellow code, i created a single Connection object by using Util() method and same will be given to my all servlets and jsp.
here my doubt is this connection object is single turn object for all my programs which means this connection object opens a one connection in a database and it sharable to all programs, so on database connection burden is reduced, then why i need to go connection pooling concept in jdbc. please anybody can clear my confusion

Jdbc.java

import java.sql.Connection;
import java.sql.DriverManager;

public class Jdbc
{
private static Connection con;
public static Connection util()throws Exception
{
if(con==null)
{
Class.forName("oracle.jdbc.OracleDriver");
con = DriverManager.getConnection("jdbcracle:thin:@localhost:1521:xe", "system", "root");
}
return con;
}
}
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So what happens when more than one person tries to use your web application?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Ignoring that this is a bad idea to begin with, the method Util() is very badly named. First of all, Java methods should start with a lowercase character. Secondly, it doesn't say anything at all about what the method does. A much better method name would be makeConnection(), or something along those lines.
 
vijay jamadade
Ranch Hand
Posts: 244
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By connection pooling may be using some server it ensures that some connections are reserved for your application with database. Once you ask for it, it gives connections from the connection pool. Make sure you close the connection once used in your program. this again makes it available in connection pool for other requests. This way connection pooling works.

Cheers !!!
 
Karthik Jayachandran
Ranch Hand
Posts: 92
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess its 'Singleton' that you are referring to, not 'Single turn' !!.


Now regarding connection pool, one obvious reason is the execution speed on multi-user environment. Obtaining a connection and then commit/rollback and closing it everytime is resource intensive and affects performance.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic