aspose file tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Locking question - URLyBird 1.2.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Reply Bookmark "Locking question - URLyBird 1.2.1" Watch "Locking question - URLyBird 1.2.1" New topic
Author

Locking question - URLyBird 1.2.1

Ericsson Liu
Greenhorn

Joined: Sep 17, 2008
Posts: 21
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.


SCJP SCJD SCWCD
Jevgeni Zhukov
Greenhorn

Joined: Aug 28, 2008
Posts: 18
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.


SCJP<br />SCJD
Ericsson Liu
Greenhorn

Joined: Sep 17, 2008
Posts: 21
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

Joined: Aug 28, 2008
Posts: 18
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

Joined: Jul 22, 2008
Posts: 100
Both the read and write options executed by a RAF should be done in a synchronized context.


SCJP, SCJD
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Locking question - URLyBird 1.2.1
 
Similar Threads
URLyBird - Lock problem
NX: createRecord(String [ ]) in URLyBird
URLyBird:1.2.1 Accessing the database
URLyBird Locking
URLyBird 1.2.3 Unnecessary locking?