If you want the threads to have their own copy of map (and hence no synchronization needed), you can use Rob's method or even simpler - just instantiate class A once per thread.
Since your original code shared the instance of class A among threads, I assume you want all the threads to work on the same map. In this case, how do you want threads to behave at the time of loading of map? Should they all load key-values in the same map simultaneously? If yes, think about colliding keys. If not, it would require a bit of synchronizations. You can't avoid it altogether.
posted 9 years ago
@Aditya : I wanted each thread to have its own copy.