• 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Preloaded servlet

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 285
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author
Posts: 111
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
They worship nothing. They say it's because nothing is worth fighting for. Like this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic