• 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.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, I'm not sure why you don't use, e.g, String.valueOf(int) in this case, but in any event...
Local variables -- variables defined and used only within a method -- can never be accessed, accidentally or on purpose, by any other method. So as long as your static methods don't use any class variables (or indirectly use the class variables of any other class) there's no danger of any interference.
 
Tarun Dewan
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest,
Thanks for your response.
Actually i have implement caching concept in my applications in which a static HashMap is populated at the time of Server startup and various other objects access it as CachingObject.getCache("ABC"). IN this method "ABC" is used for lookup thus code for this caching object is as follows :
hashmap.get("ABC").
I hope this will also not cause any issue.
Eagerly waiting for your reply.
Thanks & regards,
Tarun Dewan.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're only calling hashmap.get(), then synchronization is not needed. If, though, you're calling put() or any other method that modifies the map, then you need to be careful. Using Collections.synchronizedMap() to get a synchonized wrapped for the HashMap would be one easy way to deal with this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!