Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

more than one instance of servlet

 
Brij Garg
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • 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
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ahh i think two mapping of same servlet in web.xml with different init-param parameter.
 
Shahnawaz Shakil
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Yes thats correct
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65221
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
  •  
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic