Forums Register Login

Connection Pool Design Issue

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
Does this tiny ad smell okay to you?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 922 times.
Similar Threads
public void init(ServletConfig)
Maintaining scalability in servlets programming
Cancel JDBC Connection when Browser Cancel
SQL Exception on refeshing the servlet.
Help with closing jdbc connections
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 04:43:10.