Hello everyone.
I have read
this thread with great interest. However, I am still a bit confused regarding the synchronisation issues surrounding physical locking. I am not so concerned about record locking as I intend to have a separate LockManager to manage that. But in a nutshell, what I would have to do is this for update and delete:
a. lock the record
b. get exclusive access to the file
c. read the record
d. update/delete
e. release exclusive access to the file
f. unlock the record
and this for read and write
a. get exclusive access to the file
b. read the record
c. release exclusive access to the file
Now, since I hope to be able to use NIO, should I synchronise on a RandomAccessFile (RAF) or on the FileChannel taken from the RAF?
I do like Bahrat's solution (matching no 3 below), but effectively, I am trying to weigh up the pros and cons of 4 different approaches as I want to make an informed decision:
1) Singleton Data class with a static class variable for the RAF/FileChannel
2) Singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
3) Non-singleton Data class with a static class variable for the RAF/FileChannel
4) Non-singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
1) Singleton Data class with a static class variable for the RAF/FileChannel
In this case, any access to the database is synchronised on the single RAF/FileChannel instance. This seems simple enough.
2) Singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
Now in this case, I am not sure. What should the physical locking be on? Should it be on the singleton Data class?
3) Non-singleton Data class with a static class variable for the RAF/FileChannel
Same as no 1 and seems simple enough
4) Non-singleton Data class with a local variable for the RAF/FileChannel in each method (read, write, update, etc)
This is the most difficult one. Should I add some sort of static variable in the Data class an do the physical locking on that?
In other words, what are the pros and cons of each? I am sure that each solution is viable, but since I look upon this assignment as a learning exercise, I want to make an informed decision and improve my knowledge. The best way to do this is to be aware of the pros and cons of each approach. Any help would be very much appreciated as I am not that knowledgeable about threading and no very little about RMI - i really have my work cut out!
Thank you
oli renard - un p'tit belge de Liege (mais qui habite en GB!)