• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

more than one instance of servlet

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ahh i think two mapping of same servlet in web.xml with different init-param parameter.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Shahnawaz Shakil
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes thats correct
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
  • reply
      Bookmark Topic Watch Topic
    • New Topic