I want to use string id to synchronization my code.
this is what I am trying to implement.
public void executeSomeCode(Object object)
{
String firstString= object.getFirstString();
String secondString= object.getSecondString();
Synchronization(firstString)
{
Synchronization(secondString)
{
//retrieve data from database and execute code here and save back them.
}
}
}
but can we use directly string for synchronisation as mention in above diagram.
I already implemented synchronization using concurrenthashmap as mention in below link and that's working fine. https://stackoverflow.com/a/54672371/11053922
edit :- to avoid deadlocks,i will use these String in a lexicographically order.