Help coderanch get a
new server
by contributing to the fundraiser

John Matman

Greenhorn
+ Follow
since Jul 14, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by John Matman

Jethro,Kah,

My locking was not up to the spec during my first submission. I have not used the object.wait,notifyall at all. My lock and unlock methods had nothing but add or remove the records from a collection(no wait,notify).


https://coderanch.com/t/189941/java-developer-SCJD/certification/Scjd-Failed-due-locking


During my second submission, i have moved my locking from client to the server side. used object.wait and notifyall. I have read many threads about locking and got the idea of how to do it.
example
synchronized(lock){
while(isLocked(recNo)){
try{

lock.wait();
......
....
}

I hope i answered your questions and good luck to you all.
16 years ago
Hello All,
Today my status was changed to pass after my re submission on 07/16/08. I am so happy today. Here is the break down. Initially i was failed due to a flaw in the locking code.

The maximum possible score is 400; the minimum to pass is 320.
General Considerations (maximum = 100): 100
Documentation (maximum = 70): 70
O-O Design (maximum = 30): 30
GUI (maximum = 40): 24
Locking (maximum = 80): 80
Data store (maximum = 40): 40
Network server (maximum = 40): 40

Total score Achieved = 384/400.
16 years ago
Hello All,
Does anybody know if i have to take the essay exam again for resubmission?

John
Andrew,
First of all sorry for posting my code. Thought my failed code would not appeal anybody.

Can IllegalMonitorStateException ever be thrown?



True. I will remove the not needed exceptions.

I don't think a Vector is a good choice




I used Vector because it is synchronized. I would consider changing it to ArrayList.

how are you ensuring that only the client who locks a record can unlock it?



All client calls goes through the interface.

The client does the lock,update,unlock as an atomic operation .

Example

Client A locks the record 5 , as well as the whole collection so no other thread is allowed to lock any record.My lock method synchronizes the whole collection object.

Client A performs the update/delete..etc and calls the unlock which removes the record no from collection and notifies other threads that the collection is unlocked for other threads use.


Client A locks record 5
* Client B starts by unlocking record 5 (don't care if it is locked or not - exception will be swallowed)
* Client B locks record 5




Andrew,
I can sense what you are saying. If i had move my locking completely
to server, then it is going to be a rewrite. I have documented that all clients should get the lock first before doing update,delete etc.
[ July 15, 2008: Message edited by: John Matman ]
Guys,
Thanks much for your answers. I did the following changes. Does this sound oK?

client code
----------------


And my database code for lock , islocked, unlock is



I did not synchronize my isLocked method.


[Edit: removed code that was beyond what our policy allows. Placed code inside UBB code tags. Andrew]
[ July 14, 2008: Message edited by: Andrew Monkhouse ]
Richard,Robert,
I have replace my sleep with wait. please tell if this brings my code to spec?

Client code
--------------


Here is my unlock method from data class.

Database code
----------------


[ July 14, 2008: Message edited by: John Matman ]

[Edit: Put code inside UBB code tags - Andrew]
[ July 14, 2008: Message edited by: Andrew Monkhouse ]
Richard,
You are right. I am not a CS student. I am a Civil Engg UG.

I got your point and move forward in that direction.

Roberto,
Thanks for your advise too.
J
Hello Robert,
I am not calling threads wait() method. I thinK you call notify or notify all only on the waiting threads. I am using the sleep method which wakes up every 100 milli seconds to check if the record is still locked.


I am guessing i am violating the spec by waking the thread up after every 100 milli seconds whether or not the record is unlocked by the locked thread.

I mean the sleeping thread is consuming the cpu cycles every 100 Ms.

On the server side you need to tell us what the "lock" object is. It appears to be some kind of Collection object



It is a Vector object. If sleeping is off the spec, then the evaluator's comment is confusing. But the spec does not say anything about using the threads sleep method and it is not deprecated.

The evaluators comment is follows

Your locking code does not block when trying to lock a locked record.


[ July 14, 2008: Message edited by: John Matman ]
Hello All,
I need your generous help in fixing my locking code. Here is what the evaluator says. I have debugged my code and everything works fine including the locking.

Major point loss for record-locking mechanism, which is not according to spec. Your locking code does not block when trying to lock a locked record.

I have implemented the client side locking. Here is the client side code.



[Edit: remainder of post removed. See my post below for reasons why. I will try and clean it up later today and return it. Andrew]
[ July 14, 2008: Message edited by: Andrew Monkhouse ]