Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Are implicit objects in JSP are thread safe???

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Session scope - Not thread safe
Context scope - Not thread safe
Request scope - thread safe (Only one thread per request)
 
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frank,
Could you please explain in detail?
TIA
 
Frank Carver
Sheriff
Posts: 7001
6
Eclipse IDE Python C++ Debian Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yup.Thats very much clear now.
Thanks a lot
 
reply
    Bookmark Topic Watch Topic
  • New Topic