Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Warning. Sybex book. p.285-286. Fundamentals error.  RSS feed

Mikalai Zaikin
Ranch Hand
Posts: 3413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!