You need to (re)read Gokul Singh's post on this thread. The only thing
that's "local" about the thisSession variable is that it's a local
reference. The session object itself is still shared, and could well be
accessed by multiple threads simultaneously.

--
Martin Cooper
Tumbleweed Communications

----- Original Message -----
From: "Bo Xu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 21, 2000 8:31 AM
Subject: Re: synchronized(HttpSession) - Why should I??


> Marc Krisjanous wrote:
>
> > Hi all,
> > I have seen the following code in some examples (reduced for email):
> >
> > doGet(request,response){
> >
> > performTask(request,response);
> >
> > }
> >
> > performTask(request,response){
> >
> >         HttpSession thisSession = request.getSession(true);
> >
> >         synchronized(thisSession){
> >                 try{
> >
> > thisSession.removeValue(HPDFv2CONSTANTS.RESULT_BEAN);
> >
> >                 }catch(Exception e){};
> >
> >         }//end sync call
> >
> > }
> >
> > Now... I believe that we do not need to synchronized the session object
> > since every request is a sperate thread which contains its own request
and
> > response object. Thus a separate instance of the request object which
means
> > a separate instance of the session object.  The individual thread will
be
> > the only one accessing the session object. We do not need to protect the
> > call to the session object.
> >
> > Is this correct??
> >
> > Best Regards
> >
> > Marc
> > [...]
>
> Hi :-)  IMO, I agree with you:
>
> now in the method *performTask(request,response)*,
> request, response and thisSession are all local fields,
> only one thread will use these local fields and the code in
> this method,  so:
> #  we can use them to lock some code, but perhaps we will not get
>     any benifit.
> #  we don't need to lock those code, because only one thread will
>     use it.
>
>
> Bo
> Nov.21, 2000
>
>
___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to