| Author |
Are page scope attributes thread-safe?
|
Arthur Huxley
Greenhorn
Joined: Dec 04, 2009
Posts: 4
|
|
|
Context scoped attributes are obviously not thread safe. Request scoped attributes are thread-safe, because the container creates only one thread per request. Session scoped attributes are not thread-safe, because a user may open several browser windows. But what about page scoped attributes? I read in http://book.javanb.com/java-server-pages-2nd/0321150791_ch14lev1sec4.html that there is in theory a concurrency problem with page scope. Can someone please explain why or why not?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56180
|
|
For the same reason that scoped variables in request scope are thread-safe, so are page-scoped variables.
The situation described in the article relates to instance variables created by using scriptlet declarations. As scriptlets are now passe, this is no longer an issue.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Arthur Huxley
Greenhorn
Joined: Dec 04, 2009
Posts: 4
|
|
Thanks for the quick reply. The book "Head First Servlets and JSP 2nd edition" page 199 explicitly says that session attributes are not thread-safe, because a user may open multiple browser windows. It seems to me that the article states that there is a similar problem with page scope. How do you interpret this (taken from the article/book page linked to in my question):
"Objects in the session scope are also safe in general, as only one user, and hence one thread, will typically be accessing a given session at any moment. This, after all, is the whole point of the session scope. It is possible for a user to open multiple browser windows and hit different pages simultaneously, which can in principle cause problems. Normally, this should not be a concern. The same is true of the page scope."
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56180
|
|
I believe that the book is stating that it's not a concern.
And it isn't.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56180
|
|
|
By the way, please check your private messages for an important administrative matter.
|
 |
 |
|
|
subject: Are page scope attributes thread-safe?
|
|
|