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 the difference between the include() and forward() methods?
What is the difference between genericservlet and httpservlet
What are the types of an http request?
Explain the jar and war files in servlet?
what is multiple server?
Is servlet synchronized?
What are all the protocols supported by httpservlet?
Does servlet have main method?
What is servlet mapping?
What is the effective way to make sure all the servlets are accessible only when user has a valid session?
How can we invoke another servlet in a different application?
What are the life cycle methods of a servlet?
What is the workflow of a servlet?
When is the servlet instance created in the life cycle of servlet? What is the importance of configuring a servlet?
How to rectify errors in java servlet while compilation?