I have a method which is invoked on object instance by 3 concurrent threads. The lock i am interested is based on value not as object. For example, If two threads (T1,T2) are processing RecordID=123 and T3 is processing RecordID=456. The method should lock only T2 and T3 should proceed with execution.
Currently, i am using Lock but it will lock T2 and T3 both if T1 gets lock.
public void doSomething(String id){
try {
lock.lock();
MyRecord r = find(id);
...
....
} finally{
lock.unlock();
}
}