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
What’s the difference between forward() and sendredirect() methods?
Define the life cycle of a servlets.
I Have A Plan to develop a Project in Struts,I want the template of struts project with Hibernate.Canany body provide me the required information?
What are common tasks performed by Servlet Container?
Why is httpservlet declared abstract?
Which http method is said to be non-idempotent and idempotent?
What is difference between jsp and servlet?
What are sessions in servlets?
Why is a constructor needed in a servlet even if we use the init method?
Explain web container.
How to commuincate between an applet and a servlet?
Can we use threads in Servlets?
How to read request headers from servlets?
What is difference between cookies and httpsession?
What is the purpose of inter-servlet communication?