aspose file tools*
The moose likes Servlets and the fly likes Difference  between Single and Multi Thread Model Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Difference  between Single and Multi Thread Model" Watch "Difference  between Single and Multi Thread Model" New topic
Author

Difference between Single and Multi Thread Model

Chandrasekhar Mangipudi
Ranch Hand

Joined: Jan 29, 2006
Posts: 118
HI. Please give me a brief explanation about SingleThreadModel and MultiThreadModel.Thanks.


Thanks & Regards,
ChandraSekharMangipudi
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42278
    
  64
Servlets are multi-threaded. That means that a single servlet instance can be called from multiple threads (created for serving multiple users) simultaneously. And that means that the servlet code needs to be thread-safe, e.g. one needs to be very careful when using instance variables.

The SingleThreadModel was an attempt at side-stepping this problem by telling the servlet container: "this servlet code is not thread-safe, so if you have two simultaneous threads wanting to execute it, either create a second instance of the servlet, or wait until the first instance is finished executing".

As it turned out, this by itself was not sufficient to guarantee thread-safety. As a consequence, the interface has been deprecated. Any servlets you write need to be written in a thread-safe manner.
In the abstract that means: Any access to shared mutable state needs to be synchronized. In practice it means to not use instance variables that can change during the lifetime of a servlet. That by itself is not sufficient, but it is the source of most thread-safety problems.


Ping & DNS - my free Android networking tools app
Chandrasekhar Mangipudi
Ranch Hand

Joined: Jan 29, 2006
Posts: 118
HI and Thanks Ulf Dittmer .Understood it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Difference between Single and Multi Thread Model