Whether you need to synchronize or not depends on how you are using the
object in question. If the Collection is a local variable or request-scope
ActionForm/JavaBean element that won't ever be accessed by more than one
thread, there is no reason to synchronize it. If it is an instance variable
on your Action (i.e. shared by many request threads), it may need to be
synchronized.

<soapbox>
Also, the general perception of the performance penalty for synchronization
is much greater than the actual performance penalty in many cases. This fear
of synchronization leads people to do stupid things sometimes. I am not
recommending synchronization where it isn't needed (that would be dumb,
too), but definitely, absolutely synchronize something if you need to to
guarantee the correct operation of your app. Make the app correct and then
optimize for performance (if necessary). Chances are, the synchronization
overhead won't be an issue. If it is, you can probably refactor the bottle
neck away in a safe manner, rather than just giving up on quality and taking
the lazy way out. DON'T compromise the correct operation of the app just for
performance, and that is especially true before you know if synchronization
will have a significant impact or not. If something needs to be synchronized
to be correct, synchronize it. That part is plain and simple. The hard part
can sometimes be figuring out if you need to synchronize something or not,
but that is a separate issue.

Here's an article called "Java theory and practice: Urban performance
legends" that is worth a read:
http://www-106.ibm.com/developerworks/java/library/j-jtp04223.html
</soapbox>

-Max

----- Original Message ----- 
From: "Michael Ruppin" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Monday, June 02, 2003 1:16 PM
Subject: Re: Collection Implementation


> Gee, isn't thread safty an issue with Struts?  I
> thought I should use synchronized Objects in my
> Actions.
>



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

Reply via email to