Why SingleThread model is deprecated in Servlets?

Showing Answers 1 - 12 of 12 Answers

akantilal

  • Jun 12th, 2007
 

In Servlet 2.4, SingleThreadModel is deprecated for a good reason mostly because it does not really provide thread safety. For example, you still have to manage synchronized access to session attribute and static variables.

So recommendation is avoid the usage of instance variables and if you do, use sychronized code block.

  Was this answer useful?  Yes

sampra

  • Mar 4th, 2008
 


In Servlet 2.4, SingleThreadModel is deprecated for a good reason mostly because it does not really provide thread safety. For example, you still have to manage synchronized access to session attribute and static variables.

  Was this answer useful?  Yes

sampra

  • Mar 6th, 2008
 

single thread model is depricated beacuse it is really very expensive to creating ins instance for each request is time consuming and  difficult

  Was this answer useful?  Yes

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.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions