package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class Offer implements Runnable { BlockingDeque bdq; public Offer(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); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Is the element added into the deque : " + bol); System.out.println("Deque after adding element : " + bdq); System.out .println("Size of deque after adding element = " + bdq.size()); } } class Offer1 implements Runnable { BlockingDeque bdq1; public Offer1(BlockingDeque bdq1) { this.bdq1 = bdq1; } public void run() { System.out.println("Elements of deque are : "); int i; boolean bol = false; for (i = 0; i < 5; i++) bdq1.offer(i); System.out.println(bdq1); System.out.println("Size of deque = " + bdq1.size()); try { Thread.sleep(1500); bol = bdq1.offer(5); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Is the element added into the deque : " + bol); if (bol == true) { System.out.println("Deque after adding element : " + bdq1); System.out.println("Size of deque after adding element = " + bdq1.size()); } else { System.out.println("The element is not added into the deque."); System.out .println("Elements and Size of deque is still \n remains same i.e. size= " + bdq1.size() + " and elements= " + bdq1); } } } public class BdqOffer { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(); BlockingDeque bdq1 = new LinkedBlockingDeque(5); Runnable a = new Offer(bdq); Runnable b = new Offer1(bdq1); new Thread(a).start(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } new Thread(b).start(); try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } }