• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt regarding locking & unlocking

 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,
At present iam working on locking and unlocking i have a doubt as follows Please go through this throughly and give me ur feed back especially i looking for MARK comments on this:

At a given point of time let say 8 clients are attacking the server to book the tickets with the following recordNo
10,12,5,12,5,7,10,12
Here my lock handles this request in the following manner

10,12,5,7 these records are allowed to book the tickets without any wait() operation.
Because i make a client to wait only if there are two request for the same record.
In case of unLock first 12 will released by 10
Likewise 5 will be released by 12, 10 will be released by 5 finally 12 is released by 12.
This is how my lock() and unlock() works i like to confirm that am i in the right path.

thanks & regards,
-rameshkumar
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case of unLock first 12 will released by 10
Likewise 5 will be released by 12, 10 will be released by 5 finally 12 is released by 12.

This sentence doesn't make sense.
The client which has the lock on 12 will only unlock 12. and then the second client that was trying to book 12 can now get the lock for 12.
as you have a wait() in your lock, do you also have a notify() in you unlock?
Mark
Mark
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark for ur immediate reply.
Mark wrote:
The client which has the lock on 12 will only unlock 12. and then the second client that was trying to book 12 can now get the lock for 12.
as you have a wait() in your lock, do you also have a notify() in you unlock?
Ramesh wrote:
I do have a notify() in my unlock()
Mark what u said above will happen when two clients try to book a ticket for recordNo 12 and one followed by another.
Mark i make a client to wait only if there are
two request for the same record. i.e in my lock() method the wait() is called only for the recordNo which is already being processed in the same block say modify are in side unlock(ie already some client is trying to book ticket for the same record). Then wait() method will be called for the second client if the recno is same as the first. Else wait wont be called. I need ur comments.
Mark Please give me some test procedures to make sure that locking and unlocking works fine.

thanks & regards,
rameshkumar

 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark for ur immediate reply.
Mark wrote:
The client which has the lock on 12 will only unlock 12. and then the second client that was trying to book 12 can now get the lock for 12.
as you have a wait() in your lock, do you also have a notify() in you unlock?
Ramesh wrote:
I do have a notify() in my unlock()
Mark what u said above will happen when two clients try to book a ticket for recordNo 12 and one followed by another.
Mark i make a client to wait only if there are
two request for the same record. i.e in my lock() method the wait() is called only for the recordNo which is already being processed in the same block say modify are in side unlock(ie already some client is trying to book ticket for the same record). Then wait() method will be called for the second client if the recno is same as the first. Else wait wont be called. I need ur comments.
Mark Please give me some test procedures to make sure that locking and unlocking works fine.

thanks & regards,
rameshkumar

 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark for ur immediate reply.
Mark wrote:
The client which has the lock on 12 will only unlock 12. and then the second client that was trying to book 12 can now get the lock for 12.
as you have a wait() in your lock, do you also have a notify() in you unlock?
Ramesh wrote:
I do have a notify() in my unlock()
Mark what u said above will happen when two clients try to book a ticket for recordNo 12 and one followed by another.
Mark i make a client to wait only if there are
two request for the same record. i.e in my lock() method the wait() is called only for the recordNo which is already being processed in the same block say modify are in side unlock(ie already some client is trying to book ticket for the same record). Then wait() method will be called for the second client if the recno is same as the first. Else wait wont be called. I need ur comments.
Mark Please give me some test procedures to make sure that locking and unlocking works fine.

thanks & regards,
rameshkumar

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately I don't have my testing program around anymore. But try making a simple Data client that locks a record, and does not unlock the record. then have another that tries to lock the same record. Have System.out.println() print status when a record is locked, when it is unlcoked, and which client. Run the first one, then after you see the display showing that it has the record locked, then run the second one. You should see nothing printed on the second one, it should look like it is in wait. Then stop the first one, and then after that you should see a display on the second one saying that it locked the record.
Hope that helps
Mark
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

In my design lock method and unlock method are called from the serverside. But i can very well change it to the clientside. I like to confirm that is it right to have it in the serverside.
At present iam testing my lock and unlock as follows. Having a Thread.sleep() and blocking the first client for some time. Mean while activate the second client. Where if both the clients are trying to book tickets for the same record. First client will book the ticket mean
while the client2 will be blocked by the wait method which will be notified by the first client.
I like to know wheather my test procedure is right please write ur comments on this.

thanks & regards,
rameshkumar.km
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.sleep()

You don't want to use sleep. Not elegant
OOPS, I thought you had that in your db package code, I realize know you meant as a test. Yes that can work, or you can have that first client only call lock, and never call unlock. Then the second client will wait and wait, until you control c the first client.
The locking is part of the db package, therefore is not on the "client-side".
Mark
 
dhana sekar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark

Thanks for the great patience and replies
i got one more doubt is it necessary to synchronize the read operation while doing the locking and unlocking of modify operation.
thanks & regards,
Dhana
 
Ramesh kumaar
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mark,
Hope u had a nice weekend. I have a doubt in unlocking. If unLock(int recNo) is called
for recordNo 20 and this calls notify().Lets assume that two threads (15,20) are in the wait() block, Now i like to know is it necessery that 20 should be
notify the same recNo from the wait() block are it can notify other record. Please clear me in this regard.
thanks & regards,
-rameshkumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic