Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Are page scope attributes thread-safe?  RSS feed

 
Arthur Huxley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arthur Huxley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe that the book is stating that it's not a concern.

And it isn't.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, please check your private messages for an important administrative matter.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!