clearly updating two maps is not atomic in below code. Any thoughts in how to achieve so without big size synchronizations?
just added more details: getFirstName() is a method which returns value from map2 so if method1 includes synchronization then getFirstName should be synchronized too on the same lock. And which lock to acquire to make this totally atomic? map1 or map2 locks?
object MyApp{
private val map1 = (new ConcurrentHashMap[String, String]).asScala
private val map2 = (new ConcurrentHashMap[String, String]).asScala
def method1(firstName:String,lastName:String) ={
.....
map1 += firstName -> lastName
map2 += lastName -> firstName
}
def getFirstName(string:lastName):Option[String] ={
map2.get(firstName)
}
}