Hi there... I'm using javaexchange (www.javaexchange.com) class as a connection pooling for my application. to set up a broker I do the following (in the init method of the servlet):
my question is: If I have several servlets, do I need to use this code in the init method of every servlet that requires database connection? What happens if I specify different pool sizes in every servlet? The way I see it is having only one servlet with this declaration. thanks
I'm not going to be a Rock Star. I'm going to be a LEGEND! --Freddie Mercury
Hi, No need to use the broker object in all the Servlets. You can use one servlet which will be instantiated when the server is started and put this broker object in the init() of the servlet and give it the application scope. Now the broker object will have the defined connections in its pool and also you will be specifying the refresh time ( it closes the connection and creates new one ) the coneections. This is given as connection broker parameters. Hope this helps.
<b>L G Goundalkar</b><br /> <a href="mailto:email@example.com" rel="nofollow">firstname.lastname@example.org</a> <br />Sun Certified Programmer for Java 2 Platform.<br />Sun Certified Web Component Developer for J2EE.
Joined: Nov 27, 2001
You can use one servlet which will be instantiated when the server is started and put this broker object in the init() of the servlet and give it the application scope.
How do I give it the application scope?? The example I put is the first servlet that it is going to be invoked. That's why I start the broker in this servlet. Now, when I created a second servlet I tried to use
but I get an error. So I guess I haven't specified the application scope. How do I do that? thanks 4 ur response cheers
Joined: Jul 05, 2001
Hi, The HttpServlet class extends the GenericServlet class which has the implementation for ServletConfig interface methods. One of those method is getServletContext(). This gives the context reference which holds the application level parameters. Servlet Context allows different servlets of the application to share data. To explain in a better way, Servlet Context is what servlets see at the servlet container. i.e. if you were in place of servlet, then the view towards the container is the Servlet context. This allows all the servlets of the application to share data. On the context object, set the connection broker attribute. i.e. context.setAttribute("conbroker", new ConnectionBroker(..)); Now you can access the connection broker object by using getAttribute(String name) method of ServletContext interface which is implemeted in GenericServlet class. Cheers.