Originally posted by Russell Wurth:
Anton,
Are you implementing a single Data class? I was going to have an instance of a Data object per client that send it's read/update data/book/unbook commands to the server
Are you suggesting a lock for each read? I was only going to lock/unlock in a map for any writing that needs to go to the file.
Russell
I was thinking about implementing a Data object per client thread on the server, but then I realized I would have to enable file locking for that to work, and file locking obviates record locking since it makes for atomic writes and reads.
So now I am thinking about implementing only one Data object on the server.
A client would call a DataImpl object, which would pass the request to DataAdapter object (which would mask the way Data object works) which would call the methods of the Data object. There would be many DataImpl objects and many DataAdapter objects, but only one Data object (synchronized.)
Yep, I would implement a lock for read also. But it depends. If you are going to synchronize on the file itself during write/read, then record locking kind of becomes a moot point, since you are assuring atomic read/write anyway. The purpose of record locking with IO facilities is to prevent other threads which cut in from modifying the same record. IO is not guaranteed for atomic write/read.
The reason NIO is not permitted on this assignment is that it obviates record locking as a concept.
With IO, you can have thread A start writing to a record and thread B cuts in and modifies the same record, for instance. IO does not guarantee atomic writes. With record locking, thread B will never get a chance to write to the same record as thread A because it will be waiting for the record to be unlocked at the HashMap.
[ July 29, 2004: Message edited by: Anton Golovin ]