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
Is it good idea to create servlet constructor?
What do you mean by a filter and how does it work?
What are the life cycle methods of the servlet?
Can filter be used as request or response?
What is the purpose of inter-servlet communication?
How do you run a servlet?
What is war file?
What is http servlet? Explain with the help of an example.
In the servlets, we are having a web page that is invoking servlets ,username and password? which is checks in database? Suppose the second page also if we want to verify
What is the disadvantage of cookies?
What are advantages of servlets over cgi?
When a client request is sent to the servlet container, how does the container choose which servlet to invoke?
Explain the difference between a web server and a web container?
What are the ways to handle multi-threading in servlets?
What is the major difference between context parameter and context attribute?