But the problem is that before the lockRecord completes an exception may occur (like RecordNotFoundException).
Thus I think to check if cookie has got a value different to zero is more sure.
There is a 3rd solution, though, and I think it is safer and easier to use as well. Writing unlock in such a way that it simply returns in case the record to unlock is not locked.
2. It's better to do both as you do in your second implementation IMO. You have your Data instance at hand, so the additional check doesn't cost you anything. What I don't know is which method the second code snippet is extracted from. What are you doing there exactly?
Sounds reasonnable, doesn't it?
My only argumentation PRO my solution is "If validation change (48h->72h)there is no reason to stop the server".
Much more indeed! But I would have kept the previous snippet, just replacing the "return" statements by a your exception: remember that in your design, the fastest access (by key) is performed on the data instance.
Eat that pie! EAT IT! Now read this tiny ad. READ IT!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton