• Post Reply Bookmark Topic Watch Topic
  • New Topic

STATIC METHODS.  RSS feed

 
Tarun Dewan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
We have a class named Format with STATIC methods which is being used for conversion of variables from one datatype to another.
For e.g: getInteger(String str) - which gives me an Integer object for String.
Is there a possibility that if multiple objects access the same method concurrently than is there any possibility of one object getting Integer equivalent of String passed by other object?
if no, Will there be any impact in case of multi CPU servers?
Thanks & regards,
Tarun Dewan.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No and No. If the methods don't use a shared resource (such as a class variable), they are thread-safe. Each method call will get its own copy of local variables (and method arguments).
BTW, are you aware of the conversion methods in the String, Integer etc. classes?
 
muthu muruges
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if it is a static method?
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if it's a static method.
All the arguments and local variables are stored on the "stack", and a new lump of "stack" is used for each call to the method. You can even call one such static method from inside itself with no threading problems. (of course you would have to make sure it knew when to stop calling itself, or you'd quickly run out of "stack").
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!