SCJP 1.4 * SCWCD 1.4 * SCBCD 1.3 * SCJA 1.0 * TOGAF 8
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
... Which deals with listener classes.Originally posted by Bryan Basham:
Context attributes are a different story. Attributes can be added, retrieved, and removed from the context object. The setAttribute, getAttribute, and removeAttribute methods on ServletContext are not thread-safe. See servlet spec section 10.5 page 83.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
PMP CSQA SCJP SCWCD SCBCD INS 21 INS 23
No, it certainly is not. Bryan said this:Originally posted by Sekhar Kadiyala:
[...] This is what exactly Brayn also said.
This is what I responded to, because as stated[1] it is absolutely false. The exam does not require you to learn things that are not true.The setAttribute, getAttribute, and removeAttribute methods on ServletContext are not thread-safe.
The 'Attributes manipulation statements' you are referring to can easily be misread to mean HttpSession.getAttribute and so on. A dangerous misunderstanding, because these methods aren't the problem. The objects you bind as attributes are. I have little to add to what Kathy wrote in this thread about it. Please carefully note the way she uses the word "threadsafe".So to make attirbutes thread-safe, either we have to use synchronization or some other mechanism, which will ensure that no two thread can have access to the 'Attributes manipulation statements'.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Little anecdote to lighten things up... I did hit this 'in the wild' on a project that uses frames. A browser will request all these frames simultaneously. The problem was that the controller we used stored some request-specific state in the user's session. Most of the time it was fine, but sometimes one subframe messed up another subframe's request and triggered an error. Such subtle threading problems can be hell to track down because they happen rarely and are hard to reproduce.Originally posted by Kathy Sierra:
[...]Even session attributes, are not guaranteed to be threadsafe, under certain circumstances (client opens a second window in their browser and... it could happen that it's perceived as a different request with the same session ID).
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Bryan, I do appreciate your point; I didn't think we had any differences of opinion in purely technical terms anyway. There is no problem with what is being expressed, just (IMHO) with the way it was put. If "ServletContext.getAttribute() is not threadsafe" means something so totally different from "ArrayList is not threadsafe", something has gone badly wrong with the terms we use, and this will leave many horribly confused about the topic. "Context attributes are not threadsafe", as Kathy put it, is much less ambiguous.Originally posted by Bryan Basham:
Please allow me to provide a code example to demonstrate my point.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Peter den Haan:
Bryan, I do appreciate your point; I didn't think we had any differences of opinion in purely technical terms anyway. There is no problem with what is being expressed, just (IMHO) with the way it was put. If "ServletContext.getAttribute() is not threadsafe" means something so totally different from "ArrayList is not threadsafe", something has gone badly wrong with the terms we use, and this will leave many horribly confused about the topic. "Context attributes are not threadsafe", as Kathy put it, is much less ambiguous.
Greg Murray:
The servlet spec is a bit wish washy on this subject and different
implementations may chose to make it safe.
Since the APIs are just the interfaces it really is down to the spec
to define what really happens in the implementations.
BluePrints has always recommended writing thread safe code
when accessing the Servlet context to maintain portability.
Originally posted by Peter den Haan:
Pedantic? Maybe. It has been my experience that bad terminology is a frequent source of threading confusion. It pays to be pedantic here.
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|