Quantcast
Channel: How do servlets work? Instantiation, sessions, shared variables and multithreading - Stack Overflow
Viewing all articles
Browse latest Browse all 9

Answer by Ved Prakash for How do servlets work? Instantiation, sessions, shared variables and multithreading

$
0
0

No. Servlets are not Thread safe

This is allows accessing more than one threads at a time

if u want to make it Servlet as Thread safe ., U can go for

Implement SingleThreadInterface(i)which is a blank Interface there is no

methods

or we can go for synchronize methods

we can make whole service method as synchronized by using synchronized

keyword in front of method

Example::

public Synchronized class service(ServletRequest request,ServletResponse response)throws ServletException,IOException

or we can the put block of the code in the Synchronized block

Example::

Synchronized(Object){----Instructions-----}

I feel that Synchronized block is better than making the whole method

Synchronized


Viewing all articles
Browse latest Browse all 9

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>