SCJP, SCJD, SCWCD, OCPJBCD
SCJP, SCJD, SCWCD, OCPJBCD
Regards,<br />Seb<br /> <br />SCJP 1.4
SCJP, SCJD, SCWCD, OCPJBCD
Regards,<br />Seb<br /> <br />SCJP 1.4
SCJP, SCJD, SCWCD, OCPJBCD
Regards,<br />Seb<br /> <br />SCJP 1.4
SCJP, SCJD, SCWCD, OCPJBCD
Regards,<br />Seb<br /> <br />SCJP 1.4
SCJP, SCJD, SCWCD, OCPJBCD
I also have a check method (isLook(int):boolean) but I not so happy about it. This method can be tricky - if you check a record state and you find it unlock - that means you can lock it without problems - and just in this moment an other thread(client) does the same stuff but is "faster" than you and he locks it before you - then exception, even if the checkMethod retuns true.
You don't have the same problems ?
Regards,<br />Seb<br /> <br />SCJP 1.4
SCJP, SCJD, SCWCD, OCPJBCD
SCJP, SCJD, SCWCD, OCPJBCD
Regards,<br />Seb<br /> <br />SCJP 1.4
No, I can't have a deadlock here because the lock operation I've used here is not synchronized
and why you throw an Exception in the case you've described.
I don't see why my example is not applicable to your LockManager
SCJP, SCJD, SCWCD, OCPJBCD
I also have a check method (isLook(int):boolean) but I not so happy about it. This method can be tricky - if you check a record state and you find it unlock - that means you can lock it without problems - and just in this moment an other thread(client) does the same stuff but is "faster" than you and he locks it before you - then exception, even if the checkMethod retuns true.
You don't have/use the synchronized methods in yout lock manager but you synchronize all the usage on the Data class(a Singleton) using the same lock.
Regards,<br />Seb<br /> <br />SCJP 1.4
Sorry, for sure, I don't get your design 100%.
synchronized(aRecordObj) {
isLock? ;
lock ;
}
SCJP, SCJD, SCWCD, OCPJBCD
final Object lock = lockManager.getLockFor(int);
synchronized (lock) {
if(!lockManager.isLocked(recId)) {
//do stuff
lockManager.lock(recId);
}
}
And now back to your solution.
You use an individual lock for each client (thread), but I don't understand is how you get the "aRecordObj" outsite of your lock manager ?
I use the same term like your example :
Regards,<br />Seb<br /> <br />SCJP 1.4
If a bad user just gains the lock and never release it then ... I must think about it.
Regards,<br />Seb<br /> <br />SCJP 1.4
5. Make sure that the process of checking if a record is locked by other thread or checking if the record is exist, before locked a record, should be keep in synchronized block.
SCJP, SCJD, SCWCD, OCPJBCD
Consider Paul's rocket mass heater. |