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 ?    5 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is servlet a controller?

576


What is the difference between the getrequestdispatcher(string path) method of javax.servlet.servletrequest interface and javax.servlet.servletcontext interface?

569


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

526


Can you use javascript in servlets?

604


How can we perform any action at the time of deploying the project?

623






What is servletconfig?

547


How to commuincate between an applet and a servlet?

592


What is the purpose of dispatcherservlet properties?

510


how the HTML data stored in web server?

1955


Why is servlet used?

686


How is a servlet implemented in code?

568


What is servlet api used for conneting database?

702


What is SingleThreadModel interface?

677


Name the packages that work with servlet?

547


Why is httpservlet declared abstract?

582