1

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?

  1. 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?

  2. If the first thread deletes the key (the whole document), what will happen to the second thread?

Tarandeep Gill
  • 1,506
  • 18
  • 34

1 Answers1

0

(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.

Nathaniel Ford
  • 20,545
  • 20
  • 91
  • 102
  • I'm using the official client library: http://www.couchbase.com/develop/java/current – Tarandeep Gill Mar 27 '13 at 04:49
  • 1
    Just so you know the client won't block for 3 seconds, but will immediately return an error when a client calls get and lock on a key that is already locked. The error returned will be EXISTS. – mikewied Mar 27 '13 at 17:14
  • 1
    Updated. The documentation on this is actually really sadly thin. – Nathaniel Ford Mar 27 '13 at 17:31
  • Sorry about that. We're currently in the process of restructuring the manual and docs, there will be much more to find in the near future! – daschl Apr 09 '13 at 06:53