If a servlet implements SingleThreadModel, then that's a hint to the servlet container that this servlet is not threadsafe, and thus a servlet instance should not be used by multiple threads concurrently. Unfortunately that's not enough to make a web application thread-safe, so STM is deprecated, and should not be used.
The way to make a web app thread-safe is to program the servlets (and other code) in a thread-safe manner. That means (amongst other things) not sharing mutable state between threads, e.g. by using instance variables in servlets, or only doing so in synchronized blocks and methods.
Ping & DNS - updated with new look and Ping home screen widget
Joined: Jul 08, 2007
Hi thanks for the reply. I was not specific about servlets being threadsafe. It was just that I am unable to understand the difference between calling a class as "singlethreadModel" or "threadsafe". Dont both the terms mean the same ?
Rgds [ October 08, 2007: Message edited by: Mike Anna ]
No. SingleThreadModel was a means to allow non-thread-safe servlets to run safely by confining them to a single thread. That's not in any way the same thing as being thread-safe; that is, safe to use across threads.
It's like saying that practicing safe driving habits, and hiding the keys to the car, are the same thing.
No. SingleThreadModel was a means to allow non-thread-safe servlets to run safely by confining them to a single thread. That's not in any way the same thing as being thread-safe; that is, safe to use across threads
ooohhkkk.. now I see. STM is just a marker interface, which would probably instantiate seperate instances of a servlet. However thread-safe really means like having a synchronised keyword around the method or code. right ?