//**************** email 0 **********************************************

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
> [...]



//**************** email 1 **********************************************
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


//**************** email 2 **********************************************
The session object is the same across all the requests (for example, many
browser
instances) from the same client. So, we need to synchronize the code to do any
changes to the session object.


//**************** email 3 **********************************************
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


//**************** email 4 **********************************************
My opinion that this is NOT TRUE.

The servlet engine takes care of accessing the objects in the Session.
I think ( i am not sure) that the putValue and getValue functions are
sychronized or
contains a sychronized block.

Any comments related to this?

Andras.

//**************** email 5 **********************************************
Akhil Gupta wrote:

> Hi Andras,
> Actually, the session object is different even for different browser
> instances even when both are logged to same site, two browsers can have same
> session id only if we right click in one browser window, and click a link
> open in a new window or from file menu open new window, but that is not
> usual, so it is that we do have two different sessions.
>
> AKHIL
>



Hi all the senders of the above emails except Bo(I think I don't need to thank
him),
Thanks for your emails! :-)  and after I read all your emails, I did a simple
testing:

0
* in computerA , I double-click the icon of NN4.7 in desktop, and start a NN4.7
   -- its name is NN4.7A1
* in computerA , I double-click the icon of NN4.7 in desktop again , and start
   the second  NN4.7  -- its name is NN4.7A2
* in computerA , I use File->New->Nevigator Window of  NN4.7A2, and start
   the 3rd  NN4.7  -- its name is NN4.7A3
* in computerA , I double-click the icon of IE5.0 in desktop again , and start
   a  IE5.0  -- its name is IE5.0A1
* in computerB , I double-click the icon of NN4.7 in desktop, and start a NN4.7
   -- its name is NN4.7B1

So now I have 5 Browsers.


1
and I use them to access my Servlet class, I put a *slow action multithread
checker* in it :

...
public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException{
int count=0;

   HttpSession thisSession = request.getSession(true);
   try{
      synchronized(thisSession){
      //synchronized(request){
         while(count<10){
         System.out.println("P1="+request.getParameter("P1")+"
thread="+Thread.currentThread());
         count++;
         Thread.currentThread().sleep(1000);
         }
      thisSession.notifyAll();
      //request.notifyAll();
      }

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<HTML><BODY>");
    out.println("from servlet_session<BR>");
    out.println("</HTML></BODY>");

    out.close();
   }catch(Exception e){...}
}


2    the following is the result of my testing:

#   NN4.7A1 and NN4.7A2 and NN4.7A3 can NOT invoke my code at the same time, my
code
    is locked to them, I guess it means the HttpSessions from them are the same
one.
#  (NN4.7A1 or NN4.7A2 or NN4.7A3) and IE5.0A1 and NN4.7B1 can invoke my code
    at the same time, my code is NOT locked to them, I guess it means the
HttpSessions
     from them are NOT the same one.
#   I can NOT use request to lock my code, I guess it means:
     as a Object,  request itself is different to every *client
accessing/thread*, but perhaps
     the *nested refrence->HttpSession* in these requests will *reference* to
the same
     Object ->HttpSession, if these client accessings are from the same browser.

#  I didn't find any difference for starting a NN4.7 between the following two
ways:
    *  double-click the icon of NN4.7 in desktop to start a new NN4.7
    * use File->New->Nevigator Window of a exsited NN4.7 to start a new NN4.7

if the above is wrong, please correct it!  thanks in advance! :-)



Bo
Nov.22, 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

Reply via email to