|
Samual Harvey<br />SCJP2<br />SCJD2
Does this design looks OK?
2. On the client side when do I have to initiate the lock record and when to unlock the record?
3. Should LockManager object instance be part of DataAccessRemote or ConnectionFactory?
2. Inside DataAccessRemote create a protected static LockManager.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
The lock manager lock method will check if the record requested for locking is not locked byt another client by scanning thru the Hashtable. If not it will perform the locking else "SHOULD I DISPLAY AN ERROR MESAGE TO THE USER"?
... else you should wait() until that record is unlock()ed, as indicated by the absense of the record in your locks collection.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Samual Harvey<br />SCJP2<br />SCJD2
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>
What does wait() here means? I am thinking it is not thread wait(). How long does the client has to wait? Can you clarify more on this.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Samual Harvey<br />SCJP2<br />SCJD2
Originally posted by Samual Harvey:
So should all these wait(), notify(), notifyAll() be used inside the LockManager class or inside the client starting class? Where should I define the run method and who should invoke start()?
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 Nate Johnson:
You should but the wait stuff in your lock manager... I am not sure what you are referring to for the run and start methods?
Samual Harvey<br />SCJP2<br />SCJD2
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>
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 Michael Morris:
Hi Samuel,
Basically, your lock method should be synchronized and if a record is already locked you should call wait(). Your unlock() should verify that the calling object owns the lock on the record it is requesting be unlocked and if it does then unlock should remove it from the HashMap. Whether a record is removed or not, unlock() should always call notifyAll(). For every wait() there should be a notify[All]() to prevent dead lock.
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Samual Harvey<br />SCJP2<br />SCJD2
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>
Samual Harvey<br />SCJP2<br />SCJD2
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>
Samual Harvey<br />SCJP2<br />SCJD2
Originally posted by Jim Bedenbaugh:
Call wait() and notifyAll()? All I did was try to lock the record. If I couldn't, I threw an exception, poppped up a JDialog and told the user to try again later. I figured that the record lock could have been caused by a crashed client and I didn't want then waiting around until the server died. I didn't implement a staleLock method. The specs didn't really seem to require a staleLock check - I read of folks who submitted and passed without it.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Michael Morris:
Well the instructions say that if a record is already locked then the lock method should block, not throw an exception. Block implies wait().
To deal with stale clients, your remote implementation class should implement the Unreferenced interface, which is called sometime after the remote gc determines that there are no reachable references to the remote object. So in the unreferenced method, you simply call unlock on all the records that the remote implementation class holds.
Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Well the instructions say that if a record is already locked then the lock method should block, not throw an exception. Block implies wait().
This is what I tried in the above code. It goes into waiting and then even if I call notifyAll() it does not come out of waiting. I am not sure whats wrong.
To deal with stale clients, your remote implementation class should implement the Unreferenced interface, which is called sometime after the remote gc determines that there are no reachable references to the remote object. So in the unreferenced method, you simply call unlock on all the records that the remote implementation class holds.
Samual Harvey<br />SCJP2<br />SCJD2
Originally posted by Samual Harvey:
What do you mean by Unreferenced Interface here? I will spend sometime on this after I fix basic lock/unlock problem I am having above.
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>
Samual Harvey<br />SCJP2<br />SCJD2
Does the lock manager has to extend thread class or implement runnable
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Originally posted by Michael Morris:
No. The threads which will run in LockManager will be created and started by RMI.
Samual Harvey<br />SCJP2<br />SCJD2
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Samual Harvey<br />SCJP2<br />SCJD2
Samual Harvey<br />SCJP2<br />SCJD2
since that is equivalent to lock the entire database, which is not desired. Second, LockManager must be a singleton ( I don't know if you used the singleton pattern, but if you use it, then follow the rest points I stated below). Third, make lock and unlock method synchronized instead of synchronizing on objects. Then, still use wait and notifyall pairs to implement the semaphore.synchronised(hashMap)
SCJP2; SCJD2;
Samual Harvey<br />SCJP2<br />SCJD2
I think the idea behind the logic is to create mutliple threads that launch LockManager.
I am not sure if synchronized(hashMap) can lock the whole database. Anyway, I'll keep working on it and will post more details.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Samual Harvey<br />SCJP2<br />SCJD2
Can I combine both singleton and syn code. Is there a problem if I make LockManager a singleton and make sure only one instance is created and then use sync code inside lock and unlock rather then making the whole method syn.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Samual Harvey<br />SCJP2<br />SCJD2
Originally posted by Samual Harvey:
On implementing Unreference Interface, I found this topic. Do you think its a good idea to do.
Also, I have this question on how to determine and handle the vice-versa. I mean how can the clients know if the server has shutdown or crashed?
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>
On implementing Unreference Interface, I found this topic. Do you think its a good idea to do.
Also, I have this question on how to determine and handle the vice-versa. I mean how can the clients know if the server has shutdown or crashed?
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
There are no great people in this world, only great challenges which ordinary people rise to meet.
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Hang a left on main. Then read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|