What exactly happens when there is nothing in the queue and the take () function is called. The API says that the method will wait, but does this mean that the processor rotates checking empty / non-empty until the element is in the queue, or does it mean that the thread is giving and will be woken up by an interrupt? If so, then I probably want to see that the queue is empty, and if it is a call to thread.yield (), to give up CPU time. My question is, do I really need to generate revenue or is some kind of internal mechanism processing this for me?
Secondly, what is the interrupted exception intended for? If I understand correctly, this means that if thread A executes this method and expects input, and another thread B calls threadA.interrupt (), then thread A will catch the thrown exception and suspend execution if it is good. Is this the right way to think about it?
source
share