I'm working on a distributed system, written in Java, which is using a Hazelcast IQueue
(non Javadoc documentation). I am using Hazelcast 3.12, and for business reasons, do not have the ability to change this version.
One one node, I have a thread calling poll
. In another thread on that same node, I am calling drainTo
, a method in the BlockingQueue
interface that IQueue
implements.
The behavior I expect to see is that any thread calling poll
(on the same node, or on a different node in the distributed system) does not see the same queue elements that I get in the drainTo
call. What I instead see is that sometimes, the thread that's running poll
sees an element that's also in the drainTo
call.
I don't see this behavior if I swap out the Hazelcast IQueue
with an undistributed LinkedBlockingQueue
. This makes sense given the answers on this question.
My questions are:
- Am I wrong in expecting that the contract of
BlockingQueue
includes this "exclusivity" in the elements seen when callingpoll
anddrainTo
in different threads? - Is there a way to get all the elements of the queue at once such that I never see any duplicate elements in this "multiple consumers" scenario?