Scripts- Server Side [Computer Associates Placement]: Sample Questions 11 - 11 of 18

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 11

Scripts- Server Side

Appeared in Year: 2004

Question

MCQ▾

Although it is not commonly done, what will you do if you want to have multiple instances of Servlet in memory and if they have to share the execution of a user request?

Choices

Choice (4)

a.

Define Single Thread model

b.

Cannot be done

c.

Question does not provide sufficient data or is vague

d.

All of the above

Answer

a.

Explanation

Single Thread model

The Sigle Thread Servlet
  • The servlet programmer should implement SingleThreadModel interface to ensure that servlet can handle only one request at a time.
  • This interface is currently deprecated since Servlet API 2.4 because it doesn՚t solves all the thread-safety issues such as static variable and session attributes can be accessed by multiple threads at the same time even if we have implemented the SingleThreadModel interface.
  • So it is recommended to use other means to resolve these thread safety issues such as synchronized block etc.
  • Simple example of Single Thread model:
  1. PublicclassSurveyServletextendsHttpServlet
  2. ImplementsSingleThreadModel
  3. {
  4.     /⚹typical servlet code, with no threading concerns
  5.     ⚹In the service method. No extra code for the
  6.     ⚹SingleThreadModel interface. ⚹/
  7.     ….
  8. }

Developed by: