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

why cant there be multiple servlets running at the same time?

 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there is a question in hfsj that says there cant be multiple instances of servlets but only one instance and many threads..why cant there be many servlets? what does this mean?
 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The book meant that there is one instance of one servlet. Each request to that servlet is served by the same instance of the servlet (in a separate thread). There can be other servlets in the application running simultaneously.

When I said "there is one instance of one servlet" here "one servlet" is one <servlet> element in the web.xml file. So if there is more than one <servlet> declaration of the same servlet class in the DD, there will be two instances of that servlet...
 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean if in the web.xml we have two same servlet classes with the same url-mapping...then two instances of the servlet will start upon recieving a request?
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you mean if in the web.xml we have two same servlet classes with the same url-mapping...then two instances of the servlet will start upon recieving a request?

No. You better not have overlapping URL spaces in your servlet mappings. But it's possible to configure the same servlet class for two different -non-overlapping- URL spaces, and in that case there will be two instances of the same servlet class (but not two instances of the same servlet).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic