This week's giveaway is in the Programmer Certification (OCPJP) forum.
We're giving away four copies of Java Mock Exams (software) and have David Mayer on-line!
See this thread for details.
Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

URLyBird Locking

 
Rod Sinclair
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

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.

Regards

Rod
 
Roel De Nijs
Sheriff
Posts: 10763
148
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rod,

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)

Kind regards,
Roel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!