• 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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Denny's DVD setDatabaseLocked method

Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I am preparaing for the OCMJD exam and I read Andrew Monkhouse and Terry Camerlengo's book (SCJD Exam with J2SE 5 platform second edition) . I read and run their source code and I have a few questions that I'd like you to answer please. Source code follows.

1- why do they call getDvdList(true); in DvdFileAccess constructor if (database == null)? I mean if (database == null), then the physical database is empty, so we cannot get any DVD list basically. Therefore, we cannot populate recordNumbers (i.e Contains an index for our primary key (UPC number) to file location.) either. This is so confusing that I feel like I must be missing something. Any thoughts?

2- I tested the DvdDatabase setDatabaseLocked(true) method (which should lock the database) in my Main method as follows.

Well I don't understand why I was able to add a second DVD after locking the database. I was expecting an exception. How can change the source code to really lock the database and avoid this.

3- If I create 3 DvdDatabase clients in my main method, I will never be able to test the ReadWriteLock mechanism because they are not Thread classes right? so how do I test the locking mechanism?

4- I am not comfortable with ReadWriteLock, Lock,Condition classes ? Do we have to use those at the professional level or can we stick with the basics (i.e Threads, synchronized methods, wait , sleep , notifyAll) and do exactly the same thing and meet the professional standard?

Below the source code for the relevant classes :

Thanks for your help.


You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic