public Reference < ? extends T > remove ( long timeout ) throws IllegalArgumentException , InterruptedException { if ( timeout < 0 ) { throw new IllegalArgumentException ( "Negative timeout value" ) ; } synchronized ( lock ) { Reference < ? extends T > r = reallyPollLocked ( ) ; if ( r != null ) return r ; long start = ( timeout == 0 ) ? 0 : System . nanoTime ( ) ; for ( ; ; ) { lock . wait ( timeout ) ; r = reallyPollLocked ( ) ; if ( r != null ) return r ; if ( timeout != 0 ) { long end = System . nanoTime ( ) ; timeout -= ( end - start ) / 1000_000 ; if ( timeout <= 0 ) return null ; start = end ; } } } }
Removes the next reference object in this queue blocking until either one becomes available or the given timeout period expires .