• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaBeans in Model 2

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Background of this question concerns a web app built using the Model 2 framework of the MVC architecture...
Can I assume that any JavaBean that I instantiate for purposes of view in JSP, by custom tags or <jsp:usebean.../>, are inherently thread-safe, as long as they're declared and instantiated within methods of the servlet instance?
From what I know on servlets and thread safety I want to say 'yes', but some feedback to the contrary (if any) would help. Thanks!
---
[ April 19, 2002: Message edited by: Toby Davis ]
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the bean is in the Session or Request scope, the that's a pretty good assumption. On the other hand if the bean is in the Application scope then it is NOT a good assumption.
Kyle
 
Toby Davis
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So even though the bean was instantiated within an implemented Action's method (within the servlet-controller's instance), and not as a class member, it's still open to multi-threading issues dependent on which scope I place it in.
I can understand, logically, why an Application scope would be open to multiple threads... it's being shared by all threads... but is this inherently assumed? Something that says request objects are thread-safe inherently as part of the JSP or servlet spec... or a request can be altered by another thread before my app processes it?
I could not find much info about threading issues in the 2.3/1.2 specs.
Threading issues are giving me a headache!
I just want to be sure I have no thread-issues with my web app - and I'm using request and session mostly, with beans that were declared and instantiated within servlet methods.
---
 
Toby Davis
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a forum thread that talks a bit about request objects needing sychronization to be thread safe.
So this leads me to believe that request is not thread-safe inherently. I'm using custom tags instead of usebean in JSP, where the bean is placed in page scope, and finding the javabean instance by doing a pageContext.findAttribute() on custom tag call.
Which means that, do I need to sychronize the instantiation and population of the JavaBean when placing it into a request scope?
---
[ April 20, 2002: Message edited by: Toby Davis ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic