• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question about Lock & Socket? Who can help ?

 
Ranch Hand
Posts: 222
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
reply
    Bookmark Topic Watch Topic
  • New Topic