I want to know which of the following are not Thread safe!
Context-scoped attributes Session-scoped attributes Request-scoped attributes Instance variables in the servlet Local variables in service method Static variables in the servlet
I know that the first 3 are not thread safe and that we have to synchronize them. What about Instance variables?? Local variables inside the service method is thread safe reason every service method runs in a seperate thread. I want to know what about Static variables and Instance variables?? Any thoughts??
Hi Jyothi, Only Request Attributes and Local variables in service method are thread safe. Request attributes are thread safe because each request will run in a separate thread and there is no chance for other threads to access the attributes of that request.
Instance variables and static variables of the servlet are not thread safe , there will be only one instance of the servlet shared by multiple threads.Every thread has acess to the instance and static variables of the servlet and hence not thread safe.
Thanks and Regards, Purna Chandra Rao. SCJP 1.4 [ January 21, 2007: Message edited by: Purna Chandra Rao ]