• 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
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!