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
Can you call a jsp from the servlet?
Why doesn’t a servlet include main()?
why we should override only no-agrs init() method.
What is string tokenizer?
What is httpservlet class?
What is the difference between the http servlet and generic servlet?
How native code can be used in a servlet?
What are the mechanisms used by a servlet container for maintaining session information?
What do you mean by cgi and what are its drawbacks?
What are the uses of servlet and what is servlet chaining?
Write all the phases defined in servlet life cycle?
Is dispatcher servlet a singleton?
What is the need of session tracking in web application?
What is the difference between context parameter and context attribute?
What is the use of welcome-file-list?