You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jerry Jalenak <Je...@LABONE.com> on 2003/12/24 16:15:05 UTC

[OT] Synchronized access to application-scoped object

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?

TIA!

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

jerry.jalenak@labone.com


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: securityincidentreporting@labone.com


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: [OT] Synchronized access to application-scoped object

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Quoting Jerry Jalenak <Je...@LABONE.com>:

> 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: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org