package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; class OfferTimeUnit implements Runnable { BlockingDeque bdq; public OfferTimeUnit(BlockingDeque bdq) { this.bdq = bdq; } public void run() { System.out.println("Elements of deque are : "); int i; boolean bol=false; for(i=0; i<5;i++) bdq.offer(i); System.out.println(bdq); System.out.println("Size of deque = "+bdq.size()); try { Thread.sleep(1000); bol = bdq.offer(5,1,TimeUnit.SECONDS); System.out.println("The element is added into the deque : "); Thread.sleep(1000); System.out.println(bol); Thread.sleep(1000); System.out.println("Deque after adding element : "+bdq); System.out.println("Size of deque after adding element = "+bdq.size()); } catch (InterruptedException e) { e.printStackTrace(); } } } public class BdqOfferTimeUnit { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(); Runnable a = new OfferTimeUnit(bdq); new Thread(a).start(); } }