SCJP 1.4<br />SCJD (BS2.1.2)
SCJP 1.4<br />SCJD (BS2.1.2)
SCJP 1.4<br />SCJD (BS2.1.2)
Originally posted by Yupp Cook:
How long were you working on it?
If you want describe your synchronization approach, too. And I ll have a comparison look, must be similar. I have a special question already: Do you synch find/delete/create/update on a common object?
SCJP 1.4<br />SCJD (BS2.1.2)
Do you need to validate the data in GUI cache against the data in file (besides making sure the record is not deleted), before updating the record ?
In other words, should the client know what data it is overwriting ?
SCJP 1.4<br />SCJD (BS2.1.2)
Originally posted by Yupp Cook:
Makes a lot of sense and keeps synchronization quite simple. Very good!
When you read/write always immediatly from/to the file how do you handle the IOExceptions that arrive in Data? Changing them into RuntimeExceptions?
SCJP 1.4<br />SCJD (BS2.1.2)
Originally posted by Yupp Cook:
No reason to have doubts with your solution, seems very sound.
Indeed I change some checked exceptions like IOException and UnsupportedEncodingException into subclassed RuntimeExceptions just to fit into the given Data schema. I feel weird doing that though.
Maybe I ll change it, but this would mean to keep a runtime copy of the records = big effort
SCJP 1.4<br />SCJD (BS2.1.2)
Originally posted by Andrew Monkhouse:
Deadlock handling does not need to be convoluted - the logic for "one client can only lock one record at a time" can be done simply, as can "clients can only lock multiple records if they lock them in numerical order". Allowing infinite locks to be granted in any order to any client can require more complex deadlock detection, but it can still be done cleanly and elegantly.
SCJP 1.4<br />SCJD (BS2.1.2)
SCJP 1.4<br />SCJD (BS2.1.2)
When the thread is again in the running state it re-checks if the
record is locked.
It also re-checks that the record is still valid. This is important as it could have been deleted while we were waiting on it.
Originally posted by Richard Brooks:
I follow your rationale here...I can see it but...it looks to me like this may be a bit of encapsulation leakage, unless I'm interpreting it incorrectly, which may well be the case. What I mean is that this seems to require that the LockManager have information about the concept of "valid" in data records, which seems a bit outside the very sleek and otherwise elegant design you've come up with for it dealing only with record numbers and locking. Which means, in an implementation sense, you have to supply something, not sure what...a data structure maybe...?..from your Data class to LockManager? Or am I just waaay out in the weeds somehere?
Originally posted by Richard Brooks:
Alan,
Yes, right. That's exactly what I was talking about. Well summarized. Thanks for the clear answer/explanation of what you've done.
Just playing devil's advocate here, understand...umkay?...cause I think thats' what'd be most helpful to both of us..okay?
<devils-advocacy>
Your implementation of how LockManager deals with the concept of record validity minimizes the leakage in terms of lines of code and simplicity of the interface between the Data class and the LockManager, yes. But...it's still there in an OO design sense. So your LockManager implementation is forever bound (by a single teeny-weeny method call, granted) to the Data class/DBAccess interface.
Just off the top of my head, though, I wonder if by letting the LockManager not care about validity of the record but letting your Data class be the only one to know/care about could be made to work? After all, the Data class is very familiar with record validity and knows how to compute it...I wonder if we could help him keep that nasty secret to himself.
That way LockManager, lucky simple-minded young scoundrel he is, could dispense locking/unlocking calls all he wanted with nary a thought about records or valiidyt. Could it be made to be incumbent on the Data class to check...once the lock was obtained...as to whether the record was still valid or not? Once "owned", in a locked sense, then Data could make up it's own mind about what to do if he got an invalid record, like throw a RecordNotFoundException or something after unlocking it....?
</devils-advocacy>
I dunno....it just seems to me with the static reference to Data removed, you'd free up LockManager to be used by other classes outside DBAccess and it'd be one less little arrow I'd need to draw on my legal pad here. That's my biggest problem, no room left on the page.
...but if this makes no sense based on what you're got, ignore me. Remember, I'm still in the almost-no-design, certainly-no-code-blue-sky stage, so everything works correctly, cleanly and perfectly in my B&S system.
Good luck,
Richard
Originally posted by Alan Morgan:
Damn that devil and his advocate...he's right again, which means more work for Alan
You're right, what I will do is have the Data.lock method which invokes LockManager.lock check if the record is still valid after the lock is received.
If not I will release the lock and throw a RecordNotFoundException.
Good catch.
Have you started thinking about deadlock avoidance as yet ?
If so any chance you could have a look at the conversation Yupp and I were having above and throw your two-cents into the mix.
You're a useful man to have around....as yet untouched by the evils of coding, so I can get a "pure" opinion off you
SCJP 1.4<br />SCJD (BS2.1.2)
My advice is to check the validity before locking, so you will never lock a invalid record.
Originally posted by John Smith:
[b]In my implementation, the client can only lock one record at a time (the book() method would simply block until the record is booked).
Originally posted by Alan Morgan:
Yupp - After having a read of this thread
https://coderanch.com/t/187162/java-developer-SCJD/certification/Dealing-Deadlocks-Stale-Locks
I got to thinking about what you said again.
In this thread John Smith says:
So its seems to me (correct me if I am wrong) that he took the same approach as you.
One question - how exactly do you "block until the record is booked" ?
Oh nearly forgot - are you fat or thin client ?
So is your book() call on the server or client and do you think it makes a difference either way ?
Thanks again,
Alan.
[ March 15, 2006: Message edited by: Alan Morgan ]
SCJP 1.4<br />SCJD (BS2.1.2)
Originally posted by Alan Morgan:
Ok Yupp I think I understand you now.
I believe mine works the same but I have to run some tests later to prove it.
So do you have a section in your choices.txt on deadlock ?
And if so do you say something simple like
"Deadlock is avoided as only 1 client can lock 1 record at any 1 time
This is acheived as the client blocks on each request...."
or something along these lines ?
Thanks again,
Alan.
Originally posted by Alan Morgan:
Ok so I ran my tests and it seems that the blocking is working in the same way for me.
I put a bit of code into my server so that if you try to lock record 1 it hangs effectively.
So with the same client you can't do anything as the result is being waited on.
This tells me that if my lock/unlock occurs in one call from a client then a client can only lock one record at a time.
Just to check I had a second client connect to the server and try to lock record 2 and that worked fine.
How does this sound ?
SCJP 1.4<br />SCJD (BS2.1.2)
Animesh Saxena<br /> <br />Open Source Developer
Animesh Saxena<br /> <br />Open Source Developer
Originally posted by Animesh Saxena:
Another thing that may be wrong is whenever u lock u try to synch on lockMap.
If another client wants to delete or update a different record he won't be able to lock it cos u have synch placed on lockMap.
True but they are not restricted from locking that record...they just have to wait until my lock operation runs which is a short time.
SCJP, OCMJD, OCMJEA
Originally posted by Oricio Ocle:
Hello all
First of all, sorry for posting without reading the whole thread...
Alan, you are right:
But think what happens in notification...
What do your specs says about locking methods?
Your server must be capable of handling multiple concurrent requests, and as part of this capability, must provide locking functionality as specified in the interface provided above. 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. Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available.
If the specified record is already locked by a different
client, the current thread gives up the CPU and consumes no CPU cycles until the record is unlocked.
SCJP, OCMJD, OCMJEA
Originally posted by Oricio Ocle:
Ok think about that:
.... But it's record has not been unlocked ...
Regards
SCJP, OCMJD, OCMJEA
All of life is a contant education - Eleanor Roosevelt. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|