File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Servlets/ThreadSafe Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlets/ThreadSafe" Watch "Servlets/ThreadSafe" New topic
Author

Servlets/ThreadSafe

Arul Raj
Greenhorn

Joined: Dec 16, 2000
Posts: 5
Weather servlets are ThreadSafe? Please Explain
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12761
    
    5
Normally servlets are not Thread safe because the same servlet object can be executing many request Threads. You can not rely on instance variables keeping information for a particular request. When designing a servlet this must be kept in mind at all times.
It is not that hard to design your servlet so that only variables that are unique to a given request / Thread are used. The API provides help with the HttpSession object that you can use to store variables for a particular user.
If you absolutely can't figure out a way to do your servlet without instance variables, then you can use the SingleThreadModel interface which forces the servlet engine to only allow one Thread to execute in a servlet object.
Bill

------------------
author of:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlets/ThreadSafe
 
Similar Threads
Difference betweeen SingleThreadModel and ThreadSafe
Thread safe J2ee applcaition
Regarding Thread-safe in Servlets
How beans in EJB3.0 are threadsafe?
are stateless beans thread safe