aspose file tools*
The moose likes JSP and the fly likes JavaBeans in Model 2 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JavaBeans in Model 2" Watch "JavaBeans in Model 2" New topic
Author

JavaBeans in Model 2

Toby Davis
Ranch Hand

Joined: Apr 09, 2002
Posts: 65
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 ]

SCJP2 (1.4)
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3879
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Toby Davis
Ranch Hand

Joined: Apr 09, 2002
Posts: 65
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

Joined: Apr 09, 2002
Posts: 65
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBeans in Model 2
 
Similar Threads
Found Missing
Synchronizing service method
Why is my servlet loaded twice?
Setting JTable model after fetching data on another thread
Swings, Threads, MVC: plz clarify