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’s the difference between forward() and sendredirect() methods?

575


Define the life cycle of a servlets.

573


I Have A Plan to develop a Project in Struts,I want the template of struts project with Hibernate.Canany body provide me the required information?

2237


What are common tasks performed by Servlet Container?

771


Why is httpservlet declared abstract?

582






Which http method is said to be non-idempotent and idempotent?

607


What is difference between jsp and servlet?

646


What are sessions in servlets?

578


Why is a constructor needed in a servlet even if we use the init method?

608


Explain web container.

569


How to commuincate between an applet and a servlet?

592


Can we use threads in Servlets?

656


How to read request headers from servlets?

564


What is difference between cookies and httpsession?

546


What is the purpose of inter-servlet communication?

592