This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are implicit objects in JSP are thread safe???

 
Murali Mohan
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Are implicit objects in JSP are thread safe???
Thanks,
Mohan
[ January 30, 2004: Message edited by: Murali Mohan ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depends. For example the request, response and exception objects are created for the current thread and therefore they are safe. The application and session objects can be accessed by several threads and therefore not thread safe.
 
Andres Gonzalez
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Session scope - Not thread safe
Context scope - Not thread safe
Request scope - thread safe (Only one thread per request)
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's important to note, though, that if you store objects in the application, session, request or page contexts, they are not guaranteed to be thread safe.
Although the request and page objects themselves are threadsafe, objects stored in them are only safe if they are not also used by other threads. Remember that one of these contexts only stores a reference to an object, not a separate copy of it.
I hope that's not too confusing.
 
bharat nagpal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank,
Could you please explain in detail?
TIA
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try.
If you create a completely new object in the method, and place it in the request context, it will be threadsafe:

If you use an existing object which is also present in one of the unsafe contexts (application or session), it will not be threadsafe:

If you use an existing object which is a static (class) or member (instance) variable in the servlet class, it will not be threadsafe:

Is that any clearer?
 
bharat nagpal
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yup.Thats very much clear now.
Thanks a lot
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic