I need to synchronize only the obj1 and obj2 of the following singleton class such that multiple threads can obtain the single instance of this class however only one thread can access obj1 or obj2 at a time.
public class Sample{
private static LinkedHashMap<String, String> obj1;
private static LinkedHashMap<String, String> obj2;
public static Sample getInstance() {
if (instance == null) {
instance = new Sample();
}
return instance;
}
private Sample() {
}
public void add(LinkedHashMap lhm){
//steps
}
public void remove(LinkedHashMap lhm){
//steps
}
}
How should i go about doing that ?