Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Servlet intances for application

 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I am preparing for SCWCD,
I have a doubt in K&B book page 124 it says There is only one instance of any particular servlet calss. But what about below scenario.

If I have mapped same servlet instance for two URL mappings, then how many instances will be created. Sample code is like


<web-app>
<servlet>
<servlet-name>MySerName1</servlet-name>
<servlet-class>MySerClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MySerName1</servlet-name>
<url-pattern>/URL1</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>MySerName2</servlet-name>
<servlet-class>MySerClass</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MySerNam2</servlet-name>
<url-pattern>/URL2</url-pattern>
</servlet-mapping>
</web-app>
 
Amirr Rafique
Ranch Hand
Posts: 324
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think in this case there will be one servlet instance and it will have two references

Guys please confirm

Thanks
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Two instances will be created, because there are two different servlets (which happen to be the same class)
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per the scenario mentioned, i too think that there will be two servlet instances created as they both refer the same class.
 
PRavi kumar
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two servelt instances will be created in container,
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's definite that two servlet instances will be created. Try writing to the server log and check for yourself!
 
Pandu Rangam
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
fine it will create two instances but it is conflicting with statement of K&B page 124. "There is only one instance of any particular servlet class"
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not conflicting. Still only one instance of each servlet is created. As far as the container is concerned, it sees them as two different servlets because that is the way you have configured them by giving different names.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't like the phrasing in the book. Here is what the spec says : For a servlet not hosted in a distributed environment (the default), the servlet container must use only one instance per servlet declaration. However, for a servlet implementing the SingleThreadModel interface, the servlet container may instantiate multiple instances to handle a heavy request load and serialize requests to a particular instance.

Note the "per servlet declaration".
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pandu,

you raised nice point.

Christophe Verre thanks for your correction.

Thanks for clearing clouds of ignorance.
Now i am feeling the SUN
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Satou kurinosuke:

Note the "per servlet declaration".


Thanks for the info. from Specification and making the things clear Satou-but-now-Christophe
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic