I have two questions. I have a multithreaded Java application. What happens when a thread calls getAndLock on a key, and immediately after that another thread calls getAndLock on the same key?
Will the second thread automatically block until the first thread has released the lock? Or, will the function call return with a null CAS value? Or, will it throw an exception?
If the first thread deletes the key (the whole document), what will happen to the second thread?
(Grain of salt; I'm only intimately familiar with pecl-memcache semantics).
The documentation says that it will try and obtain a lock for three seconds and then return OperationTimeoutException
. (As mikeweid points out) If a lock already exists, it should return immediately and indicate that the key exists in the error message, but the documentation does not say what exception/error is thrown in this case.
As for the second question, if the first thread deletes a key it should return as though that key never existed; in this case null
.