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
What is the difference between CGI and Servlet?
Name the different ways of session tracking.
How to handle exceptions thrown by application with another servlet?
Explain the steps involved in placing a servlet within a package?
What do you mean by annotations in servlet?
What is the requirement of servlet config and servlet context implemented and how are they implemented?
How does tomcat servlet container work?
Differentiate between get and post?
What is the use of httpservletrequestwrapper and httpservletresponsewrapper?
Why filter is used in servlet?
Which application server is best for java?
List the Different types of servlet?
How to find whether a parameter exists in the request object?
Can servlet have a constructor ?
How can you run a servlet program?