Hi Everyone
I have been reading all the different mails on this site and have found the information incedibly useful however I have a question concerning the fact that there have been many references to there being only one Data instance and it should be passed to the individual Connection Objects created for each client.
In my assignment the data store uses a RandomAccessFile to access the data so if each client is using the same instance of the Data object then at any one time only one operation can be taking place, whether a read or a write, because of the shared FilePointer. The 'seek() then read()' or 'seek() then write()' must be atomic and synchronized to prevent another thread from moving the FilePointer in the middle of the seek() and second method call so there can never be any truly concurrent DB access.
If each client were to receive its own instance of the Data class (the recordCount would be made static and its access synchronized) then there could be concurrent access for each client on the data store as each would have its own FilePointer and multiple clients could be reading the same record at the same time if need be.
If a client wanted to modify the data store then they would have to get a lock on the particular record by storing their ID in a static Collection used by all of the clients so the lock(), read(), modify(), write() unlock() sequence would still be atomic and write operations would be sequential.
Please tell me if my thinking is incorrect as I can't see any way to get away from the problem of the shared FilePointer as can't see that having sequential Data class operations is really concurrent.
Many thanks and kindest regards
Sam
I have been reading all the different mails on this site and have found the information incedibly useful however I have a question concerning the fact that there have been many references to there being only one Data instance and it should be passed to the individual Connection Objects created for each client.
In my assignment the data store uses a RandomAccessFile to access the data so if each client is using the same instance of the Data object then at any one time only one operation can be taking place, whether a read or a write, because of the shared FilePointer. The 'seek() then read()' or 'seek() then write()' must be atomic and synchronized to prevent another thread from moving the FilePointer in the middle of the seek() and second method call so there can never be any truly concurrent DB access.
If each client were to receive its own instance of the Data class (the recordCount would be made static and its access synchronized) then there could be concurrent access for each client on the data store as each would have its own FilePointer and multiple clients could be reading the same record at the same time if need be.
If a client wanted to modify the data store then they would have to get a lock on the particular record by storing their ID in a static Collection used by all of the clients so the lock(), read(), modify(), write() unlock() sequence would still be atomic and write operations would be sequential.
Please tell me if my thinking is incorrect as I can't see any way to get away from the problem of the shared FilePointer as can't see that having sequential Data class operations is really concurrent.
Many thanks and kindest regards
Sam