• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

servlets

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hai!

What is meant by ThreadSafe?
Thanks in Advance. Bye...
M.VijayaLakshmi.
 
Tony Alicea
Desperado
Sheriff
Posts: 3226
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Prabu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic