if a client(thread) called e.g. lock(34) twice in a row, what should the behavior of lock() be then?
Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Yes, same thing should happen, -- the second lock() should wait() until it is notified that the record was unlocked
eugene, I am little confused here. If the client has to wait for the unlock to lock it again, shouldn't the server side lockmanager be doing this? Lets say for example, there are 20 clients trying to book 1 seat on record number 34 at the same time.If I am understanding this right, from the client I let Client 2 wait till the first client has unlocked record no 34 ,then I let client 2 do the lock- modifying-unlocking then client 3 and so on and so forth.
If I do what you have suggested; by ensuring that while a client is processing a lock-modify-unlock, all other clients wait till the first one finishes;
If I do what you have suggested; by ensuring that while a client is processing a lock-modify-unlock, all other clients wait till the first one finishes; then am I not ensuring that on the server there is only one thread at one time trying to lock the same record? Then there would be no need to handle multiple thread's on the server
Consider Paul's rocket mass heater. |