> Hi
>  
> This is not a problem. String s is an instance variable in the service
> method of the generated servlet. Each user gets a local copy of the
> instance variables.
>  
> Hermod

hi!
no, it is not. mention that emma said 
<% s="something" %>
and *not*
<% String s="something" %>
(and s is declared within a <%!  ... %> declaration block and therefore has
global scope)
in the 2nd case you are right, s is a local variable in the service method
and therefore synchronization is not necessary.
to emma:
does your app use sessions? in that case you can bind arbitrary objects
to the session object (setAttribute(..)/getAttribute) which are "global" to
all objects that use the same session
(and you would have to synchronize access from jsps/servlets using the same
session object, which is
not very regulary the case because usually the user accesses one page after
another, but be careful nevertheless e.g. in case of frames...)
the same jsp/servlet in a different session has it's own session object with
it's own objects bound to it,
so there are no synchronization issues here.
what exactly are you trying to achieve? perhaps it is easier to answer then.
greetings

> 
> -----Opprinnelig melding-----
> Fra: Emmanuel Eze [mailto:[EMAIL PROTECTED]]
> Sendt: 15. august 2002 13:43
> Til: JDJList
> Emne: [jdjlist] Re: Thread-Safe JSP
> 
> 
> Thanks Craig.
>  
> Assuming that I have this : <%! String s = "whatever"; %>
> and somewhere in the JSP I have: <% s="something" %>
>  
> How can I synchronize the second block?  What do u think will happen
> when different threads executes the second block?
>  
> Thanks.
> Emma
>  
>  
> 
> -----Original Message-----
> From: Craig Malmfeldt [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, August 15, 2002 2:29 PM
> To: JDJList
> Subject: [jdjlist] Re: Thread-Safe JSP
> 
> 
> 
> Emma,
> 
> If you are declaring variables within the jsp you need to be careful how
> you are doing it. If for example you declare a variable within the code
> blocks <%!        String s = "whatever"; %>
> 
> This variable has global application scope for that jsp. Any changes in
> other methods would have to be synchronized or you are not thread safe.
> 
> However, if you declare a variable within a jsp within code blocks 
> 
> <%  String s = "whatever"; %> then you need not worry about
> synchronization as this variable is declared within the service method
> of the jsp ( doGet, doPost) and each individual call to the jsp creates
> a new thread for the service method. 
> 
> Craig
> 
> 
> 
> >Dear All, 
> > 
> >Is it necessary to synchronize methods in JSP so as to make them thread
> 
> > 
> >safe? When do I need to synchronize them? Again, if for instance my
> method 
> > 
> >need to return multiple values, in which case I'm forced to use
> instance 
> > 
> >variables since Java can only return a value. How can I make the JSP
> thread 
> > 
> >safe? 
> > 
> >Emma 
> > 
> >To change your membership options, refer to: 
> >http://www.sys-con.com/java/list.cfm 
> 
>   _____  
> 
> Chat with friends online, try MSN Messenger: Click Here
> <http://g.msn.com/1HM1ENUS/c144??PS=47575> 
> To change your membership options, refer to: 
> http://www.sys-con.com/java/list.cfm 
> 
> 
> 
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> *
> 
> This email with attachments is solely for the use of the individual or
> entity to whom it is addressed. Please also be aware that DnB cannot
> accept any payment orders or other legally binding correspondence with
> customers as a part of an email. 
> 
> This email message has been virus checked by the virus programs used
> in the DnB Group.
> 
> * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
> *
> 
> 
> 
> To change your membership options, refer to:
> http://www.sys-con.com/java/list.cfm
> 

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm

Reply via email to