Forums Register Login

more than one instance of servlet

+Pie Number of slices to send: Send
"It is important to note that there can be more than one instance of a given Servlet class in the servlet container. For example,

1) If there was more than one servlet definition that utilized a specific servlet class with different initialization parameters

2) by implementing SingleThreadModel interface.

can someone help me in understanding point 1.

thanks
+Pie Number of slices to send: Send
ahh i think two mapping of same servlet in web.xml with different init-param parameter.
+Pie Number of slices to send: Send
As explained by Sunny the case 1) will occur when you have different servletConfig parameters for same servlet class.
2) situation will come if you implement singleThreadModel interface. If you are implementing this interface then it means you are telling the container that you want only one thread to access the servlet object at a given time. Container ensures this by pooling the object of servlet class. Hence you will have more than one instance of the same servlet and container assigns different instances to different threads,
+Pie Number of slices to send: Send
For the first point .. what i come to find by now is ......

Some fragment from web.xml
-------------------------------------------------------
<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
<init-param>
<param-name>Name</param-name>
<param-value>Brij</param-value>
</init-param>
</servlet>

<servlet>
<servlet-name>firstservlet</servlet-name>
<servlet-class>FirstServlet</servlet-class>
<init-param>
<param-name>Name</param-name>
<param-value>Garg</param-value>
</init-param>
</servlet>

--------------------------------------------------------------
I think this is the example where we have 2 instances for the same servlet.
+Pie Number of slices to send: Send
Yes thats correct
+Pie Number of slices to send: Send
 

Originally posted by bittoo garg:
For the first point .. what i come to find by now is ......


Just a few points:
  • It's not a great idea to use the same names, but with different casing. That would be very confusing.
  • Always be sure to put your classes in a package other than the default.
  • Whose rules are you playing by? This tiny ad doesn't respect those rules:
    a bit of art, as a gift, that will fit in a stocking
    https://gardener-gift.com


    reply
    reply
    This thread has been viewed 1124 times.
    Similar Threads
    How is Servlet a singleton?
    why cant there be multiple servlets running at the same time?
    can there ba more than one instance of servlet of a servlet at one time?
    when init() is being called?
    Is Servlet Singelton
    More...

    All times above are in ranch (not your local) time.
    The current ranch time is
    Mar 28, 2024 23:23:09.