Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
In my copy of the assignment (> 2 years ago), the javadoc for unlock() had a statement to the effect that a call to unlock for a record no longer owned by the client should be ignored.
If an attempt is made to unlock a record that has not been locked by this connection, then no action is to be taken.
Ah, but beware of race conditions!Originally posted by Eugene Kononov:
But the way I interpreted it is this:
If the record is not locked (not in the collection), ignore the call to unlock (do not remove anything from collection).
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Peter den Haan posted:
You don't need the synchronized blocks -- just use synchronized methods, they are easier to grok.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
quote:
--------------------------------------------------------------------------------
Originally posted by Eugene Kononov:
But the way I interpreted it is this:
If the record is not locked (not in the collection), ignore the call to unlock (do not remove anything from collection).
--------------------------------------------------------------------------------
Ah, but beware of race conditions!
Client A calls unlock(123).
Client B calls lock(123).
Client A calls unlock(123) again.
Now what?
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Consider yourself correctedOriginally posted by Ramesh kumaar:
Here in the bellow code i think its not adviseable to use notifyAll(), Instred u can use notify(). Correct me if am wrong.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
LockManager instances and "locks" have a 1:1 relationship. Functionally, it doesn't matter on which you synchronize -- but synchronizing on the lock manager makes your code easier to read.
Two things.Originally posted by Eugene Kononov:
Peter, what if I want to use my LockManager as a pure service class, with all its methods static [...] I *have* to synchronize on locks.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
How many databases have you ever used that had just one table? -- at some point in the future, you will want to use multiple RecordLockManagers.
public void bookFlight() {
...
data.lock(record);
data.getRecord();
data.modify(record);
data.unlock(record);
...
}
1) Instead of keeping a private instance of Data in your ConnectionFactory, create another Factory called DataFactory and pass the database file name to the DataFactory to get the Data instance.
Then you can pass the Data instance to the Connection object.
It is ok to lock/unlock in the local mode.
Hello Peter, Iam waiting for ur reply.
If a client wants to book a ticket first he should own the lock by calling lock method...
No. No. No. No. Changed my mind. Wanna come down. To see this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|