public void waitForMessageToArrive(){
  LOG.info("Waiting for message to arrive");
  long start=System.currentTimeMillis();
synchronized (messages) {
    try {
      while (hasReceivedMessage()) {
        messages.wait(4000);
      }
    }
 catch (    InterruptedException e) {
      LOG.info("Caught: " + e);
    }
  }
  long end=System.currentTimeMillis() - start;
  LOG.info("End of wait for " + end + " millis");
}

public void waitForMessageToArrive ( ) { LOG . info ( "Waiting for message to arrive" ) ; long start = System . currentTimeMillis ( ) ; synchronized ( messages ) { try { while ( hasReceivedMessage ( ) ) { messages . wait ( 4000 ) ; } } catch ( InterruptedException e ) { LOG . info ( "Caught: " + e ) ; } } long end = System . currentTimeMillis ( ) - start ; LOG . info ( "End of wait for " + end + " millis" ) ; }
use to wait for a single message to arrive .
