This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
a developer chooses to avoid using SingleThreadModel but wants to ensure that data is updated in a thread-safe manner. which two can support this design goal ? (Choose two) A. Store the data in a vocal variable B. Store the data in an instance variable c. Store the data in the HttpSession object D. Store the data in the ServletContext object E. Store the data in the ServletRequest object
The answer is A,D. I don't understand that. Could anybody help me ?
I think the first one wud be volatile variable and not vocal. volatile variables are thread safe since the jvm ensures reading these variables from the source and not from the copy maintained by each thread.
Hi Narendra, Yes,By default servlet supports multithreading. So the information in the local variables and information in the HttpServletRequest Object are Thread safe.Because For each client request,new ServletRequest Object and new ServletResponse object and new Thread will be created.After the execution of service(HttpServletRequest,HttpServletResponse) method these newly created HttpServletRequest,HttpServletResponse and Thread executed that service() method becomes candidates for garbage collection.In other way...HttpServletRequest Object is also local to service(HttpServletRequest,HttpServletResponse).So always information in the local variables are Thread safe. Bye, Krish.