Hi,
> > If I have a static method I'm calling from a JSP
> > such as:
> >
> > public static String cleanString(String s, String
> > validCharSet)
> >
> > Do I need to synchronize it? I'm assuming I don't
> > unless it accesses static
> > data. Is this correct?
>From my understanding, if you are modifying an instance variable of some
sort, then you would need to sync the method. However, if you are passing in
two strings that are each "new" objects, then you wouldn't, because each
thread of the JSP calling the static method would have its own instance of
those two variables, and each thread gets its own stack. Thus, each
thread/jsp calling the method with its own two instances of the variables
would have those variables pass onto that threads stack, and only that
thread has access to its own stack.
static data would require sync because more than one thread would access the
same static "class" variable.
Remember though..if your just reading a value, you never have to sync. Only
if you are going to modify that value and its an instance variable of an
object that more than one thread can access at the same time. Like another
poster said, if the object is application scope, then you might want to sync
the method, because all the threads access the same one object.
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets