How to take object form BlockingQueue?

I have a class X, classMachine, class Z, all of them are Threads. When Machine threads are initialized, they are put on a BlockingQueue firstQueue. Inside machines’ run method there is a while loop which checks if its boolean variable should be true or false. When it is true, machine should be put on BlockingQueue secondQueue

secondQueue.put(this);

and Z class can take it from there. If machine thread returns false, class X can take machine from firstQueue and work on it.
Now, my question is: when boolean is true, is it possible to make Machine take itself from firstQueue?
PS.I know that the question might be unclearly asked, but I don’t know how to form it properly. If anyone knows to make it better, please correct it.


Source: java

Leave a Reply