Win a copy of Hands On Software Engineering with Python this week in the Jython/Python forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Liutauras Vilda
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Ron McLeod
  • Ganesh Patekar
  • salvin francis
Bartenders:
  • Tim Holloway
  • Carey Brown
  • Stephan van Hulst

The ReservationsManager Class In Monkhouse Book  RSS feed

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the ReservationsManager class(Page 154,Topic:Creating Our Logical Reserve Methods)
it has there variables:





---------------------
And a part of reserveDVDMethod :



At the beginning of the method,it already has the lock.
but in the if statement it calls the await() method.Which lock
is the thread waiting for?
----------------------------------------------------------------
In the description of the reserve method,it says:
We have decided to allow any UPC to be reserved, even if no such record exists. This ensures that a DVD can also be reserved when we are first adding it to the system.
If the DVD not exist,how can we reserve it?I was really confused.
[ August 25, 2007: Message edited by: Merlin Chen ]
 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

the second lock (i.e lockReleased.await()) you are waiting until signaled in the releaseDvd() IF UPC is already reserved.

regarding your other part of the question:
how do you reserve: by adding the upc to the reservations HashMap, so that doesn't require the existance of the upc in the DB. now if the record is new you are adding the upc of the new record to the reservations (to lofically lock it), which means that you don't want to allow others to reserve this upc until you are done.

hope that helped
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database
https://coderanch.com/t/704633/RavenDB-Open-Source-NoSQL-Database
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!