• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servletContext and database

 
Surya Vamshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was going through HF servlets and jsp book, I read that in a class that implement servletContextListener we can define the connection to database and then use that in rest of application. I want to know how we can do that. what init parameter do we have to provide in DD.

Thanks
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If this is to be a production app, you probably don't want all requests sharing a single connection to the database.
Have you looked into the connection pooling options provided by your application server?
 
Surya Vamshi
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ben Souther:
If this is to be a production app, you probably don't want all requests sharing a single connection to the database.
Have you looked into the connection pooling options provided by your application server?


What is connection pooling. What is the disadvantage of sharing a single connection to the database.
Also want to know how to pass the parameter from to class that implements servlecontextlistener.
 
Makarand Parab
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Surya Vamshi
Do one thing, go to sun website and search for J2ee specification pdf. It will answer all your questions.

Regards
Makarand Parab
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Surya Vamshi:


What is connection pooling. What is the disadvantage of sharing a single connection to the database.
Also want to know how to pass the parameter from to class that implements servlecontextlistener.


The biggest disadvantage is that all your requests (Servlets are multi-threaded) will have to queue up for their turn with this single connection.

A connection pool creates and stores multiple connections and lends one to each thread, as it's needed. When the thread is done, it returns the connection to be re-used -- avoiding the overhead of creating a new connection for each request.

See:
http://jakarta.apache.org/commons/dbcp/
for a quick expanation.
 
Rajesh Agarwal
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Makrand" let us not suggest where we can find articles. We assume that a person would have come to this forum after seeing all of them, but still if the doubts are not cleared, they look for experts to do it.

So let us provide direct answers, which help more than just pointers to links. I am sure in case of doubts we all search for it in google first ann then look out for options
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic