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 is Servlets and explain the advantages of Servlet life cycle?
What is the major difference between servlet and applet?
What must be implemented by all servlets?
Why is httpservlet declared abstract?
What are common tasks performed by Servlet Container?
Which application server is best for java?
Explain the role of dispatcherservlet and contextloaderlistener.
Why is init() method is used in servlets?
Which interface should be implemented by all servlets?
What are the types of protocols supported by httpservlet ?
How to create war file?
Define context initialization parameters.
Why is http protocol called as a stateless protocol?
What are all the advantages of servlet over cgi?
Explain web container.