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 exactly are the functions of servlet?
When Servlet is unloaded?
How do you configure a centralized error handler in servlets?
Whether we can get deadlock situation in servlets?
What is api in servlet?
What is cgi?
What if we pass negative value in load-on-startup?
Can filter be used as request or response?
What is java servlet session?
What is the difference in between the httpservlet and generic servlet?
What is a server side include (ssi)
What is servlet mapping?
What is the use of httpservletrequestwrapper and httpservletresponsewrapper?
how the HTML data stored in web server?
Which application server is best for java?