methods that don't access member variables
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, June 7, 2004 02:41 AM

I a method per se threadsafe if it doesn't make use of any global variables? I think about code like this. String examplemethod(String a) { String lowerA = toLowerCase(a); ... [some time consuming tasks] String result = someOtherMethod(lowerA); ... return result } If a second Thread enters the method and sets lowerA, does this affect the first Thread that might be just before calling someOtherMethod(lowerA)? Or is it a totally different instance of "lowerA"?    More>>

I a method per se threadsafe if it doesn't make use of any global variables? I think about code like this.



String examplemethod(String a) {


String lowerA = toLowerCase(a);

...

[some time consuming tasks]

String result = someOtherMethod(lowerA);

...

return result

}



If a second Thread enters the method and sets lowerA, does this affect the first Thread that might be just before calling someOtherMethod(lowerA)? Or is it a totally different instance of "lowerA"?

   <<Less

Re: methods that don't access member variables

Posted By:   Anjani_Kalyan  
Posted On:   Tuesday, June 8, 2004 09:20 PM

No there should not be any problem with local vars. Each thread would get its own copy of the local vars.
About | Sitemap | Contact