struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Noah Levitt <nlev...@columbia.edu>
Subject Re: thread safety
Date Fri, 14 Jun 2002 04:59:32 GMT
On Thu, Jun 13, 2002 at 09:07:58PM -0700, Craig R. McClanahan wrote:
> 
> Not always.  Example -- let's say you have a String property (very common
> in a form bean), so you have a setter like:
> 
>   private String foo = null;
> 
>   public String getFoo() {
>     return (this.foo);
>   }
> 
>   public void setFoo(String foo) {
>     this.foo = foo;
>   }
> 
> These methods do not need to be synchronized, because the assignments are
> atomic.

Ah, indeed you are right. I was under the impression that
their atomicity was platform-dependent, but I see from the
java language spec that I was mistaken.

> 
> > Would you also agree that every call to
> > session.setAttribute() and session.getAttribute() needs to
> > be synchronized?
> 
> Absolutely not.  The container takes care of ensuring that this call is
> thread safe on its internal implementation.
> 

That's a relief. And I see that access to the attributes is
synchronized in org.apache.catalina.session.StandardSession.
I didn't find any reassuring words in the servlet api,
though. Is the requirement stated somewhere?

Thanks for your help.

Noah

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


Mime
View raw message