Hi Meena,
As you may notice, I have put your code inside a [code] block which ensures that indentation is kept. This makes your code more readable, which may help you to get more comments - there are some people who will not read code that is not formatted. If you edit your post above,
you should be able to see the start and end code block statements. Also you can look at the
UBB code description page.
Now as to your problem ....
I noticed that you are using the 'this' reference to track ownership of the lock. This implies you have one instance of the Data class per connected client. If I am wrong then the remainder of these comments do not apply.
If you have one instance of Data class per connected client, then synchronizing the lock and unlock methods does nothing for you. They are only synchronized within the thread itself, not against other threads.
Therefore if two threads try and lock the same record simultaneously, they will be in separate instances of the Data class, and so will not block each other. Therefore they could both determine that the record is not currently locked, so both lock their own record. Coincedentally they will both
appear to have worked (although not really - they updated concurrently, not one after the other).
Meanwhile the third client came in moments later and determined that the record was locked. So it goes into wait() state, waiting until this thread notifies it that it can wake up. Does something in what I just said strike you as incorrect
Regards, Andrew