• 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
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Connection Pool Design Issue

 
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a search Servlet. The init method creates a search class which is an insatnce on the servlet. If a method is invoked on the servlet it will invoke it on the search class. The Search class gets a connection from the pool and returns it back at the end of the method completion.
Is this an appropriate design? My question is if the web server creates several insatnces of the servlet(will it?)- will the init method be invoked each time- I would want that- as I want each insatnce of the servlet to have its own search class?
If this is OK. How and when do I close the connections or my connection pool?
Thanks a lot guys,
Sanjay
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Sanjay,
The Servlet container will create several instances of the Servlet only when you implement SingleThreadModel, otherwise only one instance of the servlet is created to handle all the requests.
And also when you are not implementing the SingleThreadModel, the init() is called only once before the first request is handled.
I hope this message is of some help to you.
George
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More importantly -- why are you reinventing the wheel? Most application servers already have JDBC 2.0-compliant connection pools, and even if you're using something like Tomcat you can download Apache Struts and get a connection pool implementation for free...
Kyle
 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will look at the struts- for the connection pool.
In any case- should I implement the Single Thread Model- if that is the only way get several instances of servlet?
Thanks a lot,
Sanjay
 
George Pavamani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think it is a good idea to implement SingleThreadModel , if your sole purpose is to obtain a seperate Connection for each request. The single thread model might slow down your process.Instead, why don't you have a helper class that would fetch you a connection for each request and use the instance of this class in the doget or dopost method. Please correct me if i am wrong
Thanks
George
 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My idea is to use a helper class and that is what I am trying to do. if you could go thru my first mail and see if am achieving that or not.
Thanks
Sanjay
 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anybody has further ideas on this. I think by not using the SingleThreadModel I am not using the pool- as I have only one instance of the helper class- that gets only one connection from the pool.
Thanks again,
Sanjay
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There may be only one servlet object but each Thread handling a request will have its own local variables - including a connection from a connection pool if so desired.
Bill
 
Tiger Scott
Ranch Hand
Posts: 223
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks.
The way I was implementing it was to create my helper class in the init() method- if that be the case I should have only one instance of the helper class for one instance of the Servlet?
TIA
Sanjy
 
It's a tiny ad. At least, that's what she said.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic