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
-----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
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

Reply via email to