Code example for ArrayBlockingQueue

Methods: sleep

0
    } 
 
    @Test 
    public void testTimedOffer() 
    { 
        final ArrayBlockingQueue<Object> q = new ArrayBlockingQueue<Object>(2);
        Thread t = new Thread(new Runnable()
        { 
            public void run() 
            { 
                try 
                { 
                    q.put(new Object());
                    q.put(new Object());
                    threadAssertFalse(q.offer(new Object(), 25, TimeUnit.MILLISECONDS));
                    q.offer(new Object(), 2500, TimeUnit.MILLISECONDS);
                    threadShouldThrow(); 
                } catch (InterruptedException success)
                { 
                } 
            } 
        }); 
 
        try 
        { 
            t.start();
            Thread.sleep(50);
            t.interrupt();
            t.join();
        } catch (Exception e)
        { 
            fail("Unexpected exception");