Hi, Ranchers. Another funny error from authors. It seems that they did not understand difference between ServletContext's parameters and attributes!!! Unbelievable, but this is true... On the page 285 we can read: ------------- If a servlet needs to acquire the port number used to access the main database, it would invoke the getServletContext() method to first get a handle to the application’s context. It then would call the getAttribute(String name) method, using the key name, to return the desired port number. Attributes are most commonly defined within the deployment descriptor, as shown in the following code snippet: ------------- below goes their excerpt from web.xml descriptor:
and in the end (!!!) : ----------- So in summary, we can say context attributes are fairly thread-safe, because they are usually set in the web.xml file and most servers do synchronize the setAttribute(...) method. ------------ LOL !!! 1. Parameters and attributes are completely different things. Parameters are thread safe, because they are immutable, I can hardly imagine that 'servlets rarely can modify context parameters' (as written in book). Which methos should we use to modify context parameter (I guess, setInitParameter() ??? ) 2. ServletContext attributes are NOT thread-safe because all servlets and JSP's has concurrent access to them. [ October 30, 2002: Message edited by: Mikalai Zaikin ]
Java Platform, Enterprise Edition 6 Web Services Developer Certified Expert Exam Study Guide and Quiz Exam 1Z0-810: Upgrade to Java SE 8 Programmer Study Guide and Quiz
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads