• 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

The ReservationsManager Class In Monkhouse Book

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic