I need to use multiple threads, some of them are running, some of them are waiting until some other threads would wake them up. Lets say I have thread A, B, C, D and want to be able to wake/sleep any thread from any other. So, for instance, I want A to have a possibility to wake/sleep B, C, D; I want B to have a possibility to wake/sleep A, C, D etc For this purpose I decided to go for BlockingQueue so that I add kind of messages to BlockingQueue i.e.
blockingQueue.put("Start A"); or blockingQueue.put("Stop A");
And this queue is shared among all the threads so that every thread waits until message for it appears. However, this approach, apparently, has a big disadvantage: when some thread is listening for message which is intended for this thread (thread A waits for message "Start A" and must ignore all other messages like "Start B" etc), it must explicitly check if message for him is in the queue so I must use .contains() method and write some code in order to implement what I need. However, perhaps, there is some kind of blocking set for this purpose. The set which would allows to do the following:
blockingSet.get(E) //wait until element E appears in the set