Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Locking question - URLyBird 1.2.1

 
Ericsson Liu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone, I've been reading the forum for a while and just started my SCJD assignment. I'm working on URLyBird 1.2.1.

First question from me, the specification states:
You may assume that at any moment, at most one program is accessing the database file; therefore your locking system only needs to be concerned with multiple concurrent clients of your server.


Does that mean shared read lock is not allowed? i.e. there will be no concurrent read? I was going to use ReadWriteLock class for locking, but it seems synchronized block is sufficient since shared read lock is not required?

Appreciate your thoughts.
 
Jevgeni Zhukov
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are planning to use RandomAccessFile for reading/writing data, then reading/writing operations should be in synchronized context.
Imagine a scenario when two threads are trying to read from different locations of the data file - one gets pointer to read from one location and then the other moves the pointer away to read from another location.
 
Ericsson Liu
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I am using RandomAccessFile. Does that mean i do not need to worry about locking on read/write to the db file since RandomAccessFile takes care of it?
 
Jevgeni Zhukov
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ericsson Liu:
Does that mean i do not need to worry about locking on read/write to the db file since RandomAccessFile takes care of it?

No, it means that you do need to synchronize on those operations so that only one thread can read/write at a time.
 
Jethro Borsje
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both the read and write options executed by a RAF should be done in a synchronized context.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic