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's the use of servletcontext?
What are all the protocols supported by httpservlet?
Name the different ways of session tracking.
How to create war file?
What do you mean by cgi and what are its drawbacks?
What is difference between get and post method?
What is the directory structure of a war file?
Explain the architechure of a servlet?
What’s the use of the servlet wrapper classes??
What exactly are the functions of servlet?
Which java application server is the best?
What are the different methods involved in the process of session management in servlets?
What is the difference between Server and Container?
What are the uses of servlets?
Can we use the constructor, instead of init(), to initialize servlet?