public static void verifyQueueWorks() throws Exception{
        BoundedBlockingQueue<Integer> queue = new BoundedBlockingQueue<>(30);
        ExecutorService writeExecutors = Executors.newFixedThreadPool(10);
        int TOTAL = 10000;
        AtomicInteger result[] = new AtomicInteger[TOTAL];
        AtomicInteger test = new AtomicInteger(0);
        for(int i = 0; i < TOTAL; i++) { 
            writeExecutors.execute(() -> {
                try {
                    int val = test.getAndIncrement();
                    result[val] = new AtomicInteger(1);
                    while(true){
                        if(queue.offer(val, (long)(Math.random()*100 + 1), TimeUnit.MILLISECONDS)){
                            break;
                        }
                    }
                } catch (InterruptedException e) {
                    System.out.println("Shutting down read thread");
                }
            });
        }
        
        ExecutorService readExecutors = Executors.newFixedThreadPool(10);
        for(int i = 0; i < TOTAL; i++) { 
            readExecutors.execute(() -> {
                try {
                    while(true){
                        Optional<Integer> r = queue.poll((long)(Math.random()*1000 + 1), TimeUnit.MILLISECONDS);
                        if(r.isPresent()) {
                            result[r.get()].incrementAndGet();
                        }
                    }
                } catch (InterruptedException e) {
                    System.out.println("Shutting down read thread");
                }
            });
        }
        
        //you can replace this with countdown latch. But I do not feel like writing all that code.
        Thread.sleep(10000);
        System.out.println("Validating result after reasonable wait");
        
        //if queue worked as expected all integers in result array should have value 2.
        for(int i=0; i < result.length; i++){
            if(result[i].get() != 2){
                throw new RuntimeException(String.valueOf(i));
            }
        }
        
        System.out.println("Shutting down executors");
        //force shutdown on read/write executor
        readExecutors.shutdownNow();
        writeExecutors.shutdownNow();
    }
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