Object synch = locks.get(recordId); if (synch == null) { synch = locks; } synchronized (synch) { while (locks.containsKey(recordId)) { synch.wait(); } locks.put(recordId, cookie);
Object synch = locks.get(recordId); if (synch == null) { synch = locks; } synchronized (synch) { while (locks.containsKey(recordId)) { synch.wait(); } locks.put(recordId, cookie);// further code
created a separate Lock class that will hold the record number and the cookie. I synchronize on this lock object.
Synchronization now i have changed and created a separate Lock class that will hold the record number and the cookie. I synchronize on this lock object.
If one person is writing rec 1 then till he does so no one will be able to write to any other record since he will have the lock for hte DBReader instance.