What I need:
I want to block a thread until I have (or I haven't) some certain object in the queue.
What I have:
The solution I made isn't very nice. It's just a loop with the sleep(1000) which searches if the object is gone from the queue or not. It isn't very nice because it spends time to sleep and spends time to search a certain object in the queue. Also I wanted to not search a queue but to see a count of references of object (if it is 2 then your queue still points on that object) but I afraid of this solution and also don't know how to realize it.
The full task:
I am writing an application which sends messages to the RabbitMQ nodes and confirms them. Before message is sent I save a message ID in the synchronized queue (because several threads send messages). When the message is confirmed my application receives an ACK with the message ID which was confirmed. The client thread (which send messages) has to be blocked and wait till he didn't receive a confirmation of the message he sent.
Is it possible to implement such a solution? Doesn't meter if we have to put an object or remove an object from the queue. Both solutions will be fine.