Hi All, I have a requirement in which I need to write the connection pool for the database in one servlet, say servlet1. Now this servlet acts as a Database connection pool for all the other servlets present in the same application. The other servlets can collect the database connection from this servlet. My concern, is how to preload the servlet1, before the request to the other servlets is send. When the request is send to the servlet then an instance of that servlet is created in the server, but for the servlet1 no request is send by the client directly. Regards Goyal
"Intelligence without ambition is a bird without wings."
Karthik Banda
Greenhorn
Joined: Oct 24, 2002
Posts: 9
posted
0
Hi , You can load a servlet instance by using java.reflect package as we do in servlet collaboration. This following may help you out.. psuedocode is as: { try { Servlet ser = ServletContext ctx.getServlet("servletName"); Class xx=Class.forName(ser.getClass().toString()); Object o=xx.newInstance(); } catch(E) { } } u will find a few exceptions like InstantiationException, IllegalAccessException, ClassNotFoundException accordingly, in case of any problem... try with this and let me know the result at karthik@electricangels.com
Sun Certified Java Programmer<br />Sun Certified Web Component Developer <br />Sun Certified Business Component Developer<br />BEA Certified Weblogic Server Specialist<br /> <br />Never Stop Questioning......
Dominic Paquette
Ranch Hand
Joined: Dec 13, 2002
Posts: 64
posted
0
I think that the container(ex.Tomcat) will create an instance of the servlet when it starts up. Correct me if I'm wrong Dominic
Kyle Brown
author
Ranch Hand
Joined: Aug 10, 2001
Posts: 3879
posted
0
My question is, why are you writing your own connection pool in this day and age? ALL of the commercial vendors provide their own connection pooling, and there are at least a dozen open-source implementations of connection pooling! Kyle
Goyal You can use the <load-on-startup> tag in the deployment descriptor to instruct the container to load and initialise the servlet as soon as it (the container) is started. Mark.
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
posted
0
Goyal, Please change your name to be compliant with JavaRanch's naming policy. Your displayed name should be 2 separate names with more than 1 letter each. We really would prefer that you use your REAL name. You can change your name: here. Thanks, Cindy
"JavaRanch, where the deer and the Certified play" - David O'Meara
Marty Hall
Author
Ranch Hand
Joined: Jan 02, 2003
Posts: 111
posted
0
My concern, is how to preload the servlet1, before the request to the other servlets is send.
If servlet1 really needs to be a servlet, use the following in web.xml:
However, if the only purpose of servlet1 is that initialization (ie, servlet1 never handles real requests), then you can use a ServletContextListener instead. More straightforward than a "servlet" that is not really a servlet but just an initializor-thing. Cheers- - Marty
Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.