• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Connection Pooling in Servlets

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone please explain me why connection pooling of database connections is done in servlets and exactly hw it is done .
thanks in advance ..
manal
 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you do a lot of database queries, opening and closing a new connection every time is very inefficient. Therefore, you want to use connection pooling. Basically, you will need to write a Java class to represent the connection pool, possibly as a singleton. When this class is instantiated, it opens a specified number of database connections. Whenever your JSP pages or servlets need to open a connection, they request it from the connection pool class instead of creating a new one. The pool class then checks if it still has an open connection and returns it, or it blocks and waits until a connection is available again.
-Mirko
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An addition to the above answer,
Connection Pool is not limited to be used for servlets. This can be used by any Database accessing servers. In fact, a similar kind of notion called as an Object Pool is also widely used to recycle the objects coz object creation time is also substantial.
Ashwin.
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is some great source code for connection pooling- go to www.coreservlets.com and go to the 18th chapter-has an example and case study- I went through it and understand connection pooling much better than I did prior to it.I believe it might even implement a singleton pattern -although I don't remember exactly.
 
Matthew X. Brown
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW- the source code is based on a book entitled- Core Servlets and JavaServer Pages, by Marty Hall- its very good.
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. I also use it. But the author overlooked to close the Statements and RedulstSet in one method. i had to fix it. Other than this the class defn is good.
regds
maha anna
 
reply
    Bookmark Topic Watch Topic
  • New Topic