This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Well I believe the instructions states that a client that does not own the lock of a record cannot call unlock. So basically any call to unlock for a record that is not locked or is locked by a different user, then nothing should happen in that call. You can always throw an exception if you want. However, if you code your application that the only time unlock is called is quickly after lock has been called, then you don't have to do anything. Meaning in your booking method you call lock-read-modify-unlock. Then all calls to unlock will be by the client that locked the record. Mark
Originally posted by Maksim Golubkow: Mark, Jim thanks for yours replies, so I have to throw SecurityException. Regards, Maksim
Hi again Maksim, are you sure your instructions state what Mark just mentioned? because I'm also doing URLyBird, and my instructions do not state this, if yours does please post a snippet of your instructions file, I want to confirm that ours is different, Thanks, TQ
Joined: Jun 04, 2003
Hi TQ, here is my instructions of the unlock method:
Releases the lock on a record. Cookie must be the cookie returned when the record was locked; otherwise throws SecurityException.
What exception should be thrown if the record was not locked before? My first implementation has thrown IllegalStateException with the message "The record was not locked by lock(...) method!" to force the user of my API to write good code. Regards, Maksim
Hi Maksim With the instruction you mentioned, you should throw SecurityException. TQ: This is in the comments before the unlock method signature in the interface definition in version 1.1.1 of UrlyBird:
Thanks Andrew, I'm doing version 1.2.2 and there is no RecordNotFoundException in the throws clause. Regards, Maksim
Ta Ri Ki Sun
Joined: Mar 26, 2002
Hi guys, I'm doing version 1.3.1, and heres my snippet
// Releases the lock on a record. public void unlock(int recNo) throws RecordNotFoundException; // Determines if a record is currenly locked. Returns true if the // record is locked, false otherwise.
I got that assignment after they mailed me to get a new download because I was missing the db file, I then planned my project for a week before starting to code, and I got a new download then as well, and my file had not changed, so I started coding to that spec and wont even think about getting another download at this point, too risky, so this is what I'm submitting. Quite strange that I also get 80 marks for locking, I hope I dont lose marks for having not implemented things they never asked for.
Ta Ri Ki Sun
Joined: Mar 26, 2002
I also still have my 1.2.1 instructions file and unlock has the following
// Releases the lock on a record. Cookie must be the cookie // returned when the record was locked; otherwise throws SecurityException. public void unlock(long recNo, long cookie) throws SecurityException;
// Releases the lock on a record. public void unlock(int recNo) throws RecordNotFoundException;
I've got a question on the lock method:
// Locks a record so that it can only be updated or deleted by this client. // If the specified record is already locked, the current thread gives up // the CPU and consumes no CPU cycles until the record is unlocked. public void lock(int recNo) throws RecordNotFoundException;
I assume this should have some call to wait() in it, but this throws an InterruptedException. Since I can't just declare it as thrown, because that changes the interface, what should I do with it? Re-throw as a RecordNotFoundException? Just ignore it (not sure if I can)? Fall over in a screaming heap and exit the server! Any thoughts?
Assignment: URLyBird 1.3.3, using Java 1.4.0_01<br />Status: Designing, Experimenting, Reading.
author and jackaroo
G'day Rob, Personally I would catch it, then rethrow it as a RecordNotFoundException, with a suitable reason. If you are using JDK 1.4 you can nest exceptions, so you could nest the InterruptedException within the RecordNotFoundException. Regards, Andrew