Having to use setAttribute()
and getAttribute(String)
in javax.servlet.ServletContext
, I cannot find any information on the intended behavoir with concurrent access. However, these operations may very well be called by different threads.
The servlet specification 3.0 states:
A servlet can bind an object attribute into the context by name. Any
attribute bound into a context is available to any other servlet
that is part of the same Web application.
However, there is no information on concurrency behavior of these operations. A look into the source code of Apache Tomcat reveals that it is implemented as a ConcurrentHashMap, thus making it effectively thread-safe.
My question is, should I always treat these operations as not thread-safe and have the application handle the synchronisation, or is there a piece of information that I am missing?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…