Hi Guys,
After much deliberation, pseudo code writing, diagram drawing and some revision of this post, I have come up with the following plan for locking. Please let me know if you think there is something I am over looking.
NOTE: I keep a static
key,value (primary key,locking instance of Data) hashmap of the currently locked records named
reservations.
to read a record from the database:
the following steps are all inside the synchronized read method of my singleton DatabaseAccess class.
1 - readLock the dbIndexLock
2 - read from the db file
3 - unlock the dbIndexLock
to update a record in the database:
the following steps are all inside the synchronized update method of my singleton DatabaseAccess class.
1 - writeLock the dbIndexLock
2 - lock the record in reservations
3 - read from the db file
4 - update the in memory record
5 - write to the updated record to file
6 - unlock the dbIndexLock
7 - unlock the record in reservations
8 - notify all
Be gentle