I am implementing the locking in URLyBird assignment. According to the spec you have to lock on an individual record before updating the database. So if different threads want to update different records they can do this simultaneously.
I dont have any problems implementing the code but was just wondering if this actually works ok when using a RandomAccessFile for the database. i.e. can two different threads write a RandomAccessFile (writing to different parts of the file) conncurrently without causing corruption.
Yes we can on 1 condition: you have to make sure writing to the database file happens in a thread-safe manner. More concrete: positioning the file pointer and writing the actual bytes should happen as an atomic operation (so no other thread can move the file pointer to another position)