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 is session tracking?
What is load-on-startup in servlet?
What are the differences between forward() method and sendredirect() methods?
How will you pass values from HTML page to the servlet?
What is Servlet API used for connecting database?
How do you define a servlet?
What is called a session?
What exactly are the functions of servlet?
How can we include static files in the jsp page?
What is difference between PrintWriter and ServletOutputStream?
what is multiple server?
What is the use of attribute in servlets?
What do you understand by mime type?
What are the phases of the servlet life cycle?
What is cgi?