aspose file tools*
The moose likes Servlets and the fly likes servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlets" Watch "servlets" New topic
Author

servlets

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
hai!

What is meant by ThreadSafe?
Thanks in Advance. Bye...
M.VijayaLakshmi.
Tony Alicea
Desperado
Sheriff

Joined: Jan 30, 2000
Posts: 3222
    
    5
The normal servlet behavior is that multiple simultaneous requests are dispatched to multiple threads concurrently accessing the same servlet instance.
If a servlet implements the SingleThreadModel interface (which is a marker interface like Serializable), the system guarantees that there will not be simultaneous access to the same servlet instance.


Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Prabu
Greenhorn

Joined: Jun 13, 2001
Posts: 6
hai,
Default value of "thread safe = true".
servlet or JSP file may be accessed by multiple users..
servlet engine creates a separate thread for each and evry user.
if u don't want your sevlet to be accesed by multiple users at a time,
you have to implement the servlet class with "singlethreadmodel"
interface.This interface does not contain any methods.It is just a flag.
In JSP,You have to set threadsafe as false
Thanx.
Prabu.U
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
For more information on writing thread-safe code, check out this section of Sun's java tutorial on synchronizing threads:
http://java.sun.com/docs/books/tutorial/essential/threads/multithreaded.html

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Prabhu
I would like to clarify my doubt with you regarding SingleThreadModel. In case of Servlet class which implements, SingleThreadModel you said that Servlet will not be accessed by two threads at a time. What I know that, In case of SingleThreadModel, we can create a pool of Instances which can be used for managing the client requests. We can also set the number of Instances to be created and one instances can be dedicated to one request. If more request come then , it will be put in Wait state.
My question is that we can create pool of instances which can be used not like one servlet instance. Please clarify.
Thanks
Rakesh
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: servlets