SCJP, SCJD, SCWCD, SCEA I.
I met a problem with the database cache. I tried to cache the database to memory with a helper class, Database
But if the rmi server and a standalone client or more are running on the same machine (...)
SCJP, SCJD, SCWCD, SCEA I.
My design is a 3 tier one, and hide the lock/unlock from the client.
SCJP, SCJD, SCWCD, SCEA I.
SCJP, SCJD, SCWCD, SCEA I.
I have another question about the business tier. Do we need to provide the implementation for business create, delete and update? I am planning to provide business create and delete, but not update. Since the update is mainly for the booking. What do you think?
Another question.
Is there any good solution for solving the client crash(may cause the deadlock)? I tried use the WeakHashMap, but met a problem. When I started the first network gui and tried to book a room for the first time, there is a error sometimes. The error is in the DataAdapter's book method. Here is the method's code.
code:
--------------------------------------------------------------------------------
lock(recNo);
read(recNo);
if the owner is blank then update(recNo, Data);
unlock(recNO)
--------------------------------------------------------------------------------
The error occured in unlock(recNo). After the update(), the key of recNo has gone in the WeakHashMap. So the unlock is failed.
But it will be OK for all the other booking after the first book. Strange.
So I use HashMap, then it is fine. But it don't have the feature of WeakHashMap that can handle the client crash.
SCJP, SCJD, SCWCD, SCEA I.
Thanks Phil, hope you will continue the talk on the deadlock detection on that thread.
Anyway, after you'll vote for the 3-tiers design, we'll discuss further about deadlock detection is you want.
Best,
Phil.
[ October 14, 2003: Message edited by: Philippe Maquet ]
SCJP, SCJD, SCWCD, SCEA I.
SCJP, SCJD, SCWCD, SCEA I.
You are right, a global discussion is much much better. But I think the deadlock(concerning the one caused by the client crash) is different for 2-tier from the one for 3-tier. (Now I think the client crash may not cause the deadlock if the lock/unlock is hidden from the client.)
So I am afraid if I start a thread of NX: 3-tier design, deadlock handling, there won't be other people joining in the thread excepts you and me.
I hope that I can solve it today, and I can submit the assignment this weekend and then take the essay next monday or tuesday.
The error occured in unlock(recNo). After the update(), the key of recNo has gone in the WeakHashMap. So the unlock is failed.
So I use HashMap, then it is fine.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP, SCJD, SCWCD, SCEA I.
So can you guys tell me what is the other cause for the dead lock? I think maybe I won't change my code anymore, and just make statements in my choice document.
But yesterday, I just change to using the Data instance as the key and Integer as the value.
must allow the user to book a selected record, updating the database file accordingly.
SCJP, SCJD, SCWCD, SCEA I.
SCJP, SCJD, SCWCD, SCEA I.
SCJP, SCJD, SCWCD, SCEA I.
Andrew, I agree with you, the client crash can't cause the deadlock in 3-tier design. Anyway, I still keep the WeakHashMap, and use the while() {lockedRecords.wait(timeout)} instead of while() {lockedRecords.wait()}.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
SCJP, SCJD, SCWCD, SCEA I.
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.
(...) whether the signature of the lock method allows deadlock handling.
There are some people who's signature for the lock() method does not allow them to handle deadlock.
As long as a local reference to a remote object exists, it cannot be garbage-collected and it can be passed in remote calls or returned to clients. Passing a remote object adds the identifier for the virtual machine to which it was passed to the referenced set. A remote object needing unreferenced notification must implement the java.rmi.server.Unreferenced interface. When those references no longer exist, the unreferenced method will be invoked. unreferenced is called when the set of references is found to be empty so it might be called more than once. Remote objects are only collected when no more references, either local or remote, still exist.
SCJP, SCJD, SCWCD, SCEA I.
SCJP, SCJD, SCWCD, SCEA I.
I interpreted this to mean no wait timeout.
Yeah, I think you are right for the interpretation of the locking istruction. I should change back to no timeout! I only think about the deadlock when I use the timeout but forgot to double check the instruction.
SCJP,SCJD,SCWCD,SCBCD,SCDJWS,SCEA
Originally posted by Joe J. Wang:
Anyway, for the locking on server side, I think if a client crashes immediatly after calls a book operation, the whole action(lock, read, update, unlock) at the server side will be completed by the local DataAdpater instance at the server side. Am I right? Andrew, please comments if you have time. Thanks!
Originally posted by Joe J. Wang:
The following is quoted from the RMI specification.
As long as a local reference to a remote object exists, it cannot be garbage-collected and it can be passed in remote calls or returned to clients. Passing a remote object adds the identifier for the virtual machine to which it was passed to the referenced set. A remote object needing unreferenced notification must implement the java.rmi.server.Unreferenced interface. When those references no longer exist, the unreferenced method will be invoked. unreferenced is called when the set of references is found to be empty so it might be called more than once. Remote objects are only collected when no more references, either local or remote, still exist.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Did you see how Paul cut 87% off of his electric heat bill with 82 watts of micro heaters? |