File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Wonder about one of the SCWCD whizlabs question?

 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in one of the whizlabs mock exams, is that the servlet can have more than one instance. The container might choose to do that, when the servlet implements the SingleThreadModel interface. Is this true of false??
 
Niranjan Deshpande
Ranch Hand
Posts: 1277
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, its true. Here are the excerpts from the spec -

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.

In the case where a servlet was deployed as part of an application marked in the deployment descriptor as distributable, a container may have only one instance per servlet declaration per Java Virtual Machine (JVMTM). However, if the servlet in a distributable application implements the SingleThreadModel interface, the container may instantiate multiple instances of that servlet in each JVM of the container.

The use of the SingleThreadModel interface guarantees that only one thread at a time will execute in a given servlet instance�s service method. It is important to note that this guarantee only applies to each servlet instance, since the container may choose to pool such objects. Objects that are accessible to more than one servlet instance at a time, such as instances of HttpSession, may be available at any particular time to multiple servlets, including those that implement SingleThreadModel.
It is recommended that a developer take other means to resolve those issues instead of implementing this interface, such as avoiding the usage of an instance variable or synchronizing the block of the code accessing those resources. The SingleThreadModel Interface is deprecated in this version of the specification.
 
Khaled Mahmoud
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Niranjan very much for this detailed explanation.
I guess I am using an older version of the Whizlabs simulator that is targeted to an older version of the SCWCD. I see questions talking about taglib tag in the deployment descriptor. When I open the Netbeans IDE , I dont see any taglib intellesense in the deplyment descriptor.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic