public boolean offer ( E e , long timeout , TimeUnit unit ) throws InterruptedException { if ( e == null ) { throw new IllegalArgumentException ( "The 'e' parameter may not be null." ) ; } ReentrantLock lock = this . lock ; lock . lockInterruptibly ( ) ; long nanos = unit . toNanos ( timeout ) ; try { do { if ( insert ( e , false ) ) { return true ; } try { nanos = notFull . awaitNanos ( nanos ) ; } catch ( InterruptedException ie ) { // Wake up another thread waiting on notFull, as the condition may be true, but this thread // was interrupted so cannot make use of it. notFull . signal ( ) ; throw ie ; } } while ( nanos > 0 ) ; return false ; } finally { lock . unlock ( ) ; } }
Inserts the specified element into this queue waiting if necessary up to the specified wait time for space to become available .