Are you going to stop accepting lock requests once a lock(-1) record comes in, or are you going to process them normally?
Don't u think it may result into deadlock in future. Not as per the current requirements, but when c client will be allowed to 2 or more locks at one time.
Are you going to stop accepting lock requests once a lock(-1) record comes in, or are you going to process them normally?
Originally posted by Eduard Jodas:
I don't think this is all very important, as long as you comment your decision and defend it.
Originally posted by Max Habibi:
BJ-
No matter what, you have to implement lock(-1), and you have to do it correctly. However, you don't have to use it.
M
Originally posted by Max Habibi:
Depending on how you implement your locking stragegy, the unlock can be free.
Originally posted by BJ Grau:
What do you mean by free?
Originally posted by BJ Grau:
if lock(-1) was interpreted to be for a special case such as server shutdown. No need to unlock(-1) when nothing is running. As long as one can clearly document why this was done the graders should not take away points.
Load the entire db into memory. This has the advantage of trivalizing
seaching speed, and minimizing your access time to the filesystem,
thus reducing the chances for an IO error. It has the disadvantage
of forcing you to keep this 'cache' and the actual database
file synchronized. You'll appreciate the latter if you've ever
built a database from scratch. This is probably the reason people are talking about locking records as they're read.
Originally posted by Robin Underwood:
I would avoid caching. This could have a performance problem with larger databases.
how did you deal with a record which was locked by a non-existing client
( or in other was what if client gets the lock and after it crash or something in his connection?
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Originally posted by Robin Underwood:
I did the lock(-1) a little differently. I set a boolean to not allow any new client locks. Then my lock(-1) method will wait until all existing client locks have been removed (either through client unlocks or expiration).
I assumed that lock(-1) would be used for system shutdown or maintenance, so clients attempting to get new locks will get an exception with the message "Database is locked", rather than having to wait for unlock(-1).
I recommended implementing unlock(-1) even if it isn't called. Mine was just a few lines of code and just reset the boolean after making sure that the client was the same one that requested the lock(-1).
Originally posted by Robin Underwood:
I keep track of each lock's expiration time. I have a background clean-up thread that cleans up stale locks. Also, a lock request will check if an existing lock is expired but not yet cleaned up.
Originally posted by Robin Underwood:
Nate,
I took the essay 7/13. Still no results yet. I sent an email to who2contact@central.sun.com and received an email back that it was assigned to an assessor on 7/15.
When did you take your exam and have you heard anything?
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
If each client gets thier own thread(as in, say, a factory based
RMI network approach), then you can use a WeakHashMap to store
locked records in. As you know, the value of a WeakHashMap is that when
a key object loses all references to it, it is released, as is the value
object. The elegence of this approach comes in using the Thread itself
as the key for the WeakhashMap, and the recordID as the value. This way,
when a thread dies, it will eventually release the record. Thus, there's no need for a reaper thread.
Originally posted by Robin Underwood:
Max, I could be wrong but I thought there was no guarantee that a client will run in the same thread when using RMI.
I keep track of each lock's expiration time. I have a background clean-up thread that cleans up stale locks. Also, a lock request will check if an existing lock is expired but not yet cleaned up.
Did you used Timer or anything else ?
Cause I think using Timer is overkill, I can't think about anything else , can you explain this for me?
Originally posted by Max Habibi:
So would I. I was wanted to point out the advantages and disadvantages of both approaches.
Best regards,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Hi Amit.
I may not be following your design, but it sounds like the client's are not allowing themselves to call unlock if they don't currently have the record. This is a clever idea, and a practical one.
However, it does not meet the requirements of the unlock method, as they were presented to me. That is, my unlock method (in the data class) required that the calls be ignored if the person attempting to unlock didn't actually own the lock. That's not what's happening in your case: in your case, your just promising that the client will not try to unlock records that they don't own. In the requirements (as I understand them), this responsibility falls on the Data class. You've deferred the responsibility to the client. It's a subtle, but important, difference.
If you decide to consider another approach here, then you'll need to provide some way for the Data class to keep track of the clients doing the locking. This will likely suggest the usage of a Map of some sort. This can be either through a ClientID, or, if each client gets their own thread, the ThreadID. I recommend the latter.
Originally posted by Nate Johnson:
Would it be better to store the current search criteria in the TableModel, then perform a search every time the table refreshes?
Thanks,
[ July 25, 2002: Message edited by: Nate Johnson ]
Originally posted by Amit Kr Kumar:
Hi Max
i agree with you that it should be done by Data but the problem is the lock() inside Data takes only record number as argument and nothing else.
Thus i can not pass the ClientID (RemoteDataAccess) object to this method ??
Will it be correct to modify the method signature of Data class to accomodate clientid ??
*********************************
Robin, how did u handled this situation
*********************************
Amit
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|