Reads and writes to the random access file cannot be multi-threaded,
so at a low level, you need one singleton object where each method
Call this class FileTalk. It also has a read() method. It may have other low-level methods; but again, every method must be synchronized.
To implement locking, we will define a Vector called Locks (again, may not be the most efficient, but I'm only considering concepts at this point).
Now, let's consider another business case; this case involves three steps:
1. Read a record in the file.
2. Undergoing a long computational step.
3. Writing to the same record.
And, without doing much work, we have shown that we can use the simpler methods of this class to read, continue in our own thread to do a long computation without stopping other threads from proceeding, and then finally write out our information.
[Note: the write method may need checks to make sure that in the intervening moments the record is still "the same" record we thought it was; but, that starts to get into details, though they are important details.]