public boolean offer(T t, long timeout, TimeUnit timeUnit) throws InterruptedException{
        if(t == null) { 
            throw new IllegalArgumentException();
        }
   
        long left = timeUnit.toNanos(timeout);
        
        //acquire lock on lock object
        lock.lockInterruptibly();
        try{
            //keep trying if you do not have space available in queue or time out is reached.
            while(count == items.length){
                if(left <= 0){
                    return false;
                }
                left = notFull.awaitNanos(timeUnit.toNanos(left));
            }
            //enqueue the item into the queue 
            enqueue(t);
            //signal notEmpty condition since queue is not empty anymore
            notEmpty.signal();
        } finally {
            //release the lock.
            lock.unlock();
        }
        return true;
    }
Offer item to queue. If queue is full wait with timeout till space is available.
@param t - item to offer
@param timeout - time out time
@param timeUnit - time out unit
@return - returns true if item was offered in queue successfully else false.
@throws InterruptedException
src/com/interview/multithreaded/BoundedBlockingQueue.java