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 dispatcher servlet?
Which java application server is the best?
What is the difference between forward () and sendredirect () functions in servlet? Explain
Difference between httpservlet and generic servlets?
How do you create a cookie using servlet?
Define the life cycle of a servlets.
request parameter how to find whether a parameter exists in the request object?
What do you mean by session tracking?
Explain the concept of ssi ?
Why do we have servlet filters?
What is the difference between CGI and Servlet?
What are the differences between forward() method and sendredirect() methods?
What do you mean by cgi?
If a servlet is not properly initialized, what exception may be thrown?
What is ServletConfig object?