Quoting Jerry Jalenak <[EMAIL PROTECTED]>:

> Craig - 
> 
> Thanks for the response.  One last question - during the time period where
> the getServletContext().setAttribute() is executing in Servlet_1, is there
> any concern about collision with an access from Servlet_2 (Struts)?  I guess
> I'm unsure whether the setAttribute() method is synchronized or not....
> (the javadoc doesn't say.)
> 

You can assume that your app doesn't have to worry about calling
getServletContext().getAttribute() from one thread, and
getServletContext().setAttribute() from another thread at the same time -- the
container guarantees that the internal data structure it is using (in the case
of Tomcat, it's a HashMap that *is* synchronized appropriately) is thread
safe.

The only objects that the application has to worry about w.r.t. thread safety
are its own.

> Thanks!
> 
> Jerry Jalenak
> Development Manager, Web Publishing
> LabOne, Inc.
> 10101 Renner Blvd.
> Lenexa, KS  66219
> (913) 577-1496
> 

Craig


> [EMAIL PROTECTED]
> 
> 
> > -----Original Message-----
> > From: Craig R. McClanahan [mailto:[EMAIL PROTECTED]
> > Sent: Wednesday, December 24, 2003 1:00 PM
> > To: Struts Users Mailing List
> > Subject: Re: [OT] Synchronized access to application-scoped object
> > 
> > 
> > Quoting Jerry Jalenak <[EMAIL PROTECTED]>:
> > 
> > > Holiday Greetings to All!
> > > 
> > > Quick design question - Is it possible to synchronize an 
> > application-scoped
> > > object between two servlets within the same web 
> > application?  I have a
> > > servlet that I have written that maintains a List object 
> > that is stored in
> > > application scope.  This servlet basically creates a new 
> > List, then replaces
> > > the existing one (uses the same name for the object).  My 
> > second servlet
> > > (Struts) simply accesses this List in a read-only fashion - 
> > no updates.  I
> > > can write a basic spin-lock type of mechanism to ensure 
> > that my Actions do
> > > not try to access this List while my first servlet is 
> > replacing the object,
> > > but I'm wondering if there is an easier approach, possibly using a
> > > synchronized block using the application object....
> > > 
> > > Comments?
> > > 
> > 
> > Synchronizing on the List instance won't help much, because 
> > of the way you're
> > replacing the old one with a new one -- but it's probably 
> > unnecessary as well,
> > since the servlet reading the old List and the servlet 
> > creating the new List
> > are never manipulating the same object instance.
> > 
> > If the servlet doing the modifying was doing it "in place" on 
> > the existing List
> > instance, then synchronizing on that instance would indeed be 
> > appropriate.
> > 
> > > TIA!
> > > 
> > > Jerry Jalenak
> > 
> > Craig
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> This transmission (and any information attached to it) may be confidential
> and
> is intended solely for the use of the individual or entity to which it is
> addressed. If you are not the intended recipient or the person responsible
> for
> delivering the transmission to the intended recipient, be advised that you
> have received this transmission in error and that any use, dissemination,
> forwarding, printing, or copying of this information is strictly prohibited.
> If you have received this transmission in error, please immediately notify
> LabOne at the following email address: [EMAIL PROTECTED]
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to