How to avoid busy spinning in Java
问题 I have a multi-threaded application where a thread sends a message to another thread. The waiting thread polls for the message and reacts (locks are handled). Like this: Waiting thread code: while(true) { if(helloArrived()) System.out.println("Got hello"); if(byeArrived()) System.out.println("Got bye"); if(stopArrived()) break; } I want to avoid this cpu hogging technique and use something else instead. Any ideas? Edit: The actual code is below: BlockingQueue<Mail> killMeMailbox = new