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
When to use doget() and when dopost()?
Should I override the service() method?
What is the use of servlet context?
Differentiate between the get and post method
If servlet receives multiple requests, how many objects will it create?
What do you mean by url pattern in servlet?
What is the workflow of a servlet?
What are the benefits of using servlet over cgi?
What is servlet and its use?
When a client request is sent to the servlet container, how does the container choose which servlet to invoke?
What is the difference between jsp and servlet life cycle?
What is the servlet?
What is URL Encoding?
What is the process to implement doget and dopost methods?
Describe in brief RequestDespatcher?