SCJP2
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP2
Stop the possibility of deadlocks by writing a deadlock detection routine (again - check if your instructions allow such a restriction)
I expect some of you check these codes.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Andrew Stop the possibility of deadlocks by writing a deadlock detection routine (again - check if your instructions allow such a restriction)
Phil Restriction ?! Could a system which whould avoid deadlocks (a very bad scenario by definition) through a detection routine bring some restriction on the locking system ?
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
If you do have a requirement to lock the entire database, then what is the logical outcome if the database is locked? Should a client be able to get a lock on an individual record while the entire database is locked? Do you prevent this from happening?
There is a restriction - you are restricted from deadlocking the system
Hmmm - one of these days I will have to learn English
There are some people who's signature for the lock() method does not allow them to handle deadlock (...)
Now according to those instructions, there is nothing I can do if deadlock occurs, except throw a RuntimeException.
I really don't like the idea of throwing RuntimeException, but I also don't like the idea of deadlock. I think throwing RuntimeException is the lesser of two evils, but you would have to be certain it was really well documented, as it is quite possible that this could catch some poor client when some future application is in production.
Which instructions did you get (including version number) ?
It's the first time I read this lock() method signature here :
"public void lock(int recNo, Object recordLocker) throws Exception".
What's the Object recordLocker parameter that you never use BTW ?
THis said, and reviewing your code, it seems OK to me, except the useless synchronized (lockMap) block in your isLocked method.
SCJP2
Do you have a requirement to lock the entire database? If not, then I would remove the entire method which locks the database.
If you do have a requirement to lock the entire database, then what is the logical outcome if the database is locked? Should a client be able to get a lock on an individual record while the entire database is locked? Do you prevent this from happening?
What is your "recordLocker" object?
I presume that this lock() method is in your LockManager. Is it being called by lock() in your Data class?
SCJP2
The lock() method does not being called in my Data class, but in my RemoteDataAccess clss.
Instructions:
Your data access class must be called "Data.java", must be in a package called "suncertify.db", and must implement the following interface:
If yes, how did you implement lock and unlock in Data ?
Notice that that sentence is a "must" one. What about implementating them by delegating their job to your LockManager ?
SCJP2
The lock/unlock method being called process is:
code:
CSRemoteDataAccesstaAccessFacade-->RemoteDataAccess-->LockManager (1)
I don't think it must be in the following steps. And the following implementation violates the SRP(Single Responsibility Principle):
code:
CSRemoteDataAccesstaAccessFacade-->RemoteDataAccess-->Data-->LockManager (2)
I mean that the probability of this situation is much bigger than at 3-tier design, where the business logic will be made at the server side. Is my assumption right?
Or do you think I still can omit this potential deadlock for my design without risking to fail the exam?
2. I don't understand why you don't want to allow a client to lock more than one record. Is that because you guys want to use the Data.this-reference as Key-Object in a WeakHashMap? And so create a DeadLockException like Phil's if Data.this allready is in the HashMap?
if a deadlock occurs because of crossed claims, the "guilty" client (the one who is initiating the deadlock situation) gets a DeadlockException thrown from his lock() call.
Getting that exception, he knows that 1) the lock he just claimed was not granted and 2) he lost a previous granted lock wihtout any way to know which one he lost. But as my lock calls are reentrant, he still may claim all the locks he needs and go on with its job.
Phil: if a deadlock occurs because of crossed claims, the "guilty" client (the one who is initiating the deadlock situation) gets a DeadlockException thrown from his lock() call.
Ulrich: I don't understand. How can there be a deadlock due to crossed lock claims?
But why do you force Client A to loose also the previous granted lock for Record 1?
And how do you ensure that the action concerning Record 1 will go on? Lets assume that the call book(recNo 1) may have been made before book(recNo 2). Further the client tries to lock Record 2 just before the update(recNo1) is made. Update(recNo1) noticed, it hasn't anymore the lock of Record1. And then? Do you have perhaps within the book-method a catch-block perhaps for SecurityException, which will call lock(recNo1) once more?
Now, I understand.
Can I just ask, how you implement your LockManager so it can check the potential deadlock?
Luckily, I suppose, most of the assignments don't impose necessity of locking multiple records at a time
Signature of the method also takes one arg not an array, so you lock-unlock one by one, which allow you for very efficient implementation.
2. Also, you might be interested to know that although the assignment require you to implement lock-unlock methods on remote client side,
In my ass. I implemented all methods they asked me, but my client lived happily without using them: all locking-unlocking was done on server-side on BEHALF of the client. This allows for easier recovery from deadlocks if they occured. (I've got full score for my implementation.)
So, maybe lock-unlock is not very hard after all.
SCJP2
If I call lock/unlock of LockManager directly in RemoteDataAccess, that is not implemte the lock/unlock of Data.
So, I thinked a lot in the past two days. Now, I want to implement a simple solution. My instruction does not need me to remember who locked a record. Just need me to implement that a record should be locked by a connection at a moment. If another client want to lock the same record, the client should wait for the record unlocked. And there is no requirement needing me to think about the multi-tables scenario.
The City calls upon her steadfast protectors. Now for a tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|