Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Lock & Socket? Who can help ?

 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am doing a SCJD project, I want to use Socket rather than RMI, but I am not clear that how to do "locking" if i use socket? does it mean if client A booked a ticket than client b cannot book it or if client A is dealing with record 1 client B cannot access record 1?
I am confused...
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi HaoZhe,
Welcome to JavaRanch.
Whether you use Sockets or RMI should have no bearing on your locking code.
What the locking could should do is logically stop two clients from modifying a record at the same time. A client must obtain the lock before it can modify the record, and only one client may own the lock for any given record at any given time.
does it mean if client A booked a ticket than client b cannot book it

Yes.
Since only one client can own the lock for a particular record at any given time, when a client obtains a lock, it can then verify if the record is still available to be booked. This will stop the situation where client b overwrites the booking made by client a.
or if client A is dealing with record 1 client B cannot access record 1?

That is up to you. Stopping any other clients from being able to read the data until after you have released the lock gives very little value (IMHO), so I wouldn't bother with it.
If you wrote your application so that the client could change their mind before finalising the transaction (effectively a commit / rollback handler) then being able to block reading would give you your first level of isolation - preventing dirty reads. However I think that this is far more than we need to worry about for this assignment.
Regards, Andrew
 
HaoZhe Xu
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
I think this is a very god forum, China has a forum similiar to this
www.chinajavaworld.com but that is not good at all. So I feel very happy here, since so many warm-heart people...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic