SCJP, SCWCD
K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
only one thread executes the lock->update->unlock process
use a service layer where only the necessary methods are exposed eg book and search
SCJP, SCWCD
Garik Ustinov wrote:But in this case, if all methods are synchronized, each thread is guaranteed to execute update() atomically, which leads us to the question: whats the point in using lock/unlock at all?
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP, SCWCD
SCJP, SCWCD
Garik Ustinov wrote:
I think Client 2 would happily overwrite Client 1 booking without hesitation regardless of our locking implementation.
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
SCJP, SCWCD
The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Garik Ustinov wrote:checking for availability prior to updating may contradict with business rules, because that would somehow complicate for example booking cancellation in future
SCJP, SCWCD
Cheers, Roberto Perillo
SCJP, SCWCD, SCJD, SCBCD
Elchin Asgarli wrote:Besides what if my Data class is meant to be used in a way that one client must be able to lock two records?
Roel De Nijs wrote:Hi Elchin,
First of all it's not my intention to make you doubt more and more
Roel De Nijs wrote:
if you have a lockCookie, you just generate a unique value and the client/thread with this unique value is allowed to delete/update the record. It does not get any easier than that.
if you don't have a lockCookie, you need a way to identify your clients, because as you know (or should know) RMI does not guarantee that a request from the same client or handled by the same thread. So you need some mechanism to identify the client, because a record locked by a client, may only be updated/deleted by that specific client. So it is a bit more work to do (then just generating a lockCookie), but you can prevent a deadlock without any problem: you (can) know exactly how many records a specific client has already locked, so when it has already locked a record, you can block another record being locked by the same client (by throwing an IllegalStateException for example).
Roel De Nijs wrote:
Your Data class could be abused if multiple records are locked by different clients in a specific order. So you'll have to add some comments (in javadoc and/or decisions document) to define proper use of the Data class (and so you give the accessor obvious indications you identified the possibility of deadlock, and you have thought about how to avoid it)
Roel De Nijs wrote:
That's not the case for this assignment, so YAGNI. And if in near future this functionality is required, you will have to create some sort of "preventing deadlock"-mechanism.
Elchin Asgarli wrote:Isn't client authentication out of scope for Data class? I think in my version of assignment it is, since its methods have cookies, and they are meant to be the only tools for handling access.
indeed YANGI
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|