public int waitForMessages ( int num_spins , final BiConsumer < Integer , Integer > wait_strategy ) throws InterruptedException { // try spinning first (experimental) for ( int i = 0 ; i < num_spins && count == 0 ; i ++ ) { if ( wait_strategy != null ) wait_strategy . accept ( i , num_spins ) ; else Thread . yield ( ) ; } if ( count == 0 ) _waitForMessages ( ) ; return count ; // whatever is the last count; could have been updated since lock release }
Blocks until messages are available