Forums Register Login

Single or multiple instances of Data class

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Sam,
You are on the right track. Some people chose an alternative design where each client gets its own instance of data, but I don't think it's very intuitive or safe.
Eugene.
+Pie Number of slices to send: Send
Thanks for your input Eugene, much appreciated.
Sam
+Pie Number of slices to send: Send
My instructions (2.5 yrs or so ago) explicitly stated that I was not to complicate the design for the sake of performance.
- Peter
+Pie Number of slices to send: Send
Thanks Peter
Yes I think I am perceiving more compexity then necssary. Having read so many books on this I am confusing what I have read with what the asssigment actually asks for. Feeling much happier about decision process now.
Sam
A wop bop a lu bop a womp bam boom! Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 680 times.
Similar Threads
RMI, threads, locking unlocking records
lock/unlock & synchronized
FBN : RAF handle and Synchronize methods
Suggested Locking Solution
Passed with 148 / 155
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 04:35:15.