Well I took the Developer exam and failed due to my locking/synchronization. I saw what I thought was the problem and corrected it...and failed again. I'm going to give it one more shot, but I can't see why I'm losing points. I'm working on the Bodgitt & Scarper contractor booking assignment.
This was the reason for failure:
- Major point loss for record-locking mechanism, which is not threadsafe. It is possible for multiple threads to concurrently obtain a lock on the same record.
I chose not to use a RandomAccessFile. Instead I keep all my record data in memory, in a DataContainer object which is just an array. Each thread gets a Data.java instance which has methods it can use to access the data in the data container ( read(), create(), modify(), delete(), etc.). After not passing, I basically made any code that I thought should be thread-safe synchronize on the DataContainer object containing the record data.
I realize this is not the best solution, but I thought it would at least solve the synchronization problem. I'm including the Data.java access class below. If any one wants to see any more code let me know. Help! I'm at a loss.
Sorry, it is not acceptable on this forum to post so much code (See our SCJD FAQ)
[ February 18, 2007: Message edited by: Barry Gaunt ]
This was the reason for failure:
- Major point loss for record-locking mechanism, which is not threadsafe. It is possible for multiple threads to concurrently obtain a lock on the same record.
I chose not to use a RandomAccessFile. Instead I keep all my record data in memory, in a DataContainer object which is just an array. Each thread gets a Data.java instance which has methods it can use to access the data in the data container ( read(), create(), modify(), delete(), etc.). After not passing, I basically made any code that I thought should be thread-safe synchronize on the DataContainer object containing the record data.
I realize this is not the best solution, but I thought it would at least solve the synchronization problem. I'm including the Data.java access class below. If any one wants to see any more code let me know. Help! I'm at a loss.
Sorry, it is not acceptable on this forum to post so much code (See our SCJD FAQ)
[ February 18, 2007: Message edited by: Barry Gaunt ]