Singleton - sharing instance methods thread-safe?
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   John_Crossman
Posted On:   Wednesday, January 23, 2002 09:57 AM

I want to implement Singleton on an object (Environment) but I question thread safety...


Environment.java has:


			
String getProperty(String prop, HashMap h);



getProperty() reads a String from a property file, then (using HashMap key/value pairs) does a replacement on that String where ${key} matches are found. The result is returned.



Thread-safe? Could two HashMaps overlap from two separate calls and cause confusion?

Re: Singleton - sharing instance methods thread-safe?

Posted By:   Anonymous  
Posted On:   Wednesday, January 23, 2002 11:48 AM

Parameters passed to a function are always specific for the calling thread. If 2 threads call this function simultaneously, they each have their own reference to their own HashMap and prop.


If the HashMap was a member variable of the class, or the Hashmap passed by the two threads is the same instance, you can expect trouble ...




Regards,


Günther Van Roey.

http://www.javacoding.net

About | Sitemap | Contact