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
To change your membership options, refer to:
http://www.sys-con.com/java/list.cfm


Reply via email to