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.
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
a bit of art, as a gift, that will fit in a stocking