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

What is dispatcher servlet?

775


Which java application server is the best?

752


What is the difference between forward () and sendredirect () functions in servlet? Explain

736


Difference between httpservlet and generic servlets?

810


How do you create a cookie using servlet?

817


Define the life cycle of a servlets.

782


request parameter how to find whether a parameter exists in the request object?

764


What do you mean by session tracking?

894


Explain the concept of ssi ?

787


Why do we have servlet filters?

770


What is the difference between CGI and Servlet?

777


What are the differences between forward() method and sendredirect() methods?

743


What do you mean by cgi?

706


If a servlet is not properly initialized, what exception may be thrown?

845


What is ServletConfig object?

813