Hi Yr,
Yes, CouchbaseQueue is safe for concurrent use by multiple threads and multiple JVMs.
The Java class itself has no mutable state. The backing array document is modified using subdocument operations (which are atomic) and optimistic locking. It should perform reasonably well as long as there’s not a huge amount of contention. Here’s the source code if you’d like to see for yourself.
A couple of things to keep in mind regarding the implementation as of SDK 2.6.1:
- The API for this class is not committed, meaning it could change at any time.
- CouchbaseQueue.poll() throws
ConcurrentModificationException
if there’s too much contention and the “compare and swap” retry limit is exceeded. The retry limit is controlled by a Java System Propertycom.couchbase.datastructureCASRetryLimit
, and defaults to10
.
EDIT: I see you were asking specifically about SDK 2.5.5 – CouchbaseQueue is the same in 2.5.5 and 2.6.1.
Thanks,
David