Is Servlet Class Thread safe?????? How to make servlet
Thread safe ???

Answer Posted / venkat

by default every servlet is not Thread safe.

if we want to make Thread safe use these statements

1) use SingleThreadModel interface . but this interface is
deprecated in servlet 2.5 specification

2) use synchronized methods and blocks

for example
=========
use synchronized method
=======================


public synchronized void service(ServletRequest
request,ServletResponse response) throws
ServletException,IOException
{
.........
.......
}

use synchronized block
========================


public void service(ServletRequest request,ServletResponse
response) throws ServletException,IOException
{
synchronized(this)
{
.........
.......
}
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is getservletcontext?

723


What are the steps that are involved in using the httpservlet class?

825


How will two or three servlets interact or communicate with each other?

1145


What do you mean by chaining in servlet?

774


What is the difference between the http servlet and generic servlet?

866


What is servlet and its use?

807


Explain mvc pattern.

760


How the servlet is loaded?

786


What mechanisms are used by a Servlet Container to maintain session information?

885


How can a servlet be used to generate plain text instead of html?

738


Is servlet synchronized?

804


How is a servlet implemented in code?

778


What is servlet and its advantages?

759


Which method is called when reference variable is passed in system.net?

2053


Why session tracking is needed?

772