Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Q about servlet instances in containers.

 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it correct to say that there must be only one instance of a servlet if that servlet does not implement SingleThreadModel interface and that there may be one or more instances of any servlet that implement SingleThreadModel???
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by leandro oliveira:
Is it correct to say that there must be only one instance of a servlet if that servlet does not implement SingleThreadModel

No . As if there is a mapping like
<servlet>
<servlet-name>First</servlet-name>
<servlet-class>com.package.Hello</servlet-class>
</servlet>
<servlet>
<servlet-name>Second</servlet-name>
<servlet-class>com.package.Hello</servlet-class>
</servlet>
Then two instances will be created for each name.This may be helpful if u want to configure multiple <init-param> for same functionality.e.g. say if com.package.Hello servlet is used for connecting to database and user want to connect to two database, then user can configure two instance for each one

there may be one or more instances of any servlet that implement SingleThreadModel???

Correct.There "may be" one or more!!!
 
Leandro Oliveira
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks! just one more question: where do I learn about these xml tags???
 
Varun Khanna
Ranch Hand
Posts: 1400
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I referred Manning, in case u can't ... try to google around
chk out links to scwcd deployment descriptor mentioned in this site !!
 
Ryan Bailey
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are absolutely correct leandro unless you explicity define another two different servlet names referring to the same class. Not saying it isn't good practices, but I don't know when you would want to do this but I'm sure there is a reason. The Manning book entitled Exam Study Kit is a great resource for finding out these tags as well as a study guide.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic