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

prathima sampelly
Greenhorn

Joined: Nov 05, 2006
Posts: 2
Are servlets&jsp s thread safe by default? if not how to make it thread safe
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by prathima sampelly:
Are servlets&jsp s thread safe by default? if not how to make it thread safe


No. The one you are talking about is the case of Single Thread Model.

In general, container creates different thread for each request and all threads execute at the same time.
Prabhu Venkatachalam
Ranch Hand

Joined: Nov 16, 2005
Posts: 502

Servlet and JSP is not Thread Safe By Dafeult.

If You want to make Servlet Thread Safe, you need to implement SingleThreadModel interface.But this is deprecated now. It not advisable to use this.

If you want make JSP thread safe, make page attribute isThreadSafe="true". but servlet class generated from JSP implements SingleThreadModel interface. So, this too is not advisable to do.

HTH,


Prabhu Venkatachalam<br />SCJP 1.4,SCWCD 1.4<br />prabhu.venkatachalam@gmail.com
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
This is too complex a question to handle in a simple forum response. Go read a servlet tutorial, then browse past discussions. You are not the first person to ask this question and there is no need for us to repeat the many discussions that have resulted.

Bill
 
Don't get me started about those stupid light bulbs.
 
subject: Servlets