package devmanuals.com; import java.util.concurrent.BlockingDeque; import java.util.concurrent.LinkedBlockingDeque; class AddLast implements Runnable { BlockingDeque bdq; public AddLast(BlockingDeque bdq) { this.bdq = bdq; } public void run() { System.out.println("Elements of deque are : "); int i; for(i=1; i<5;i++) bdq.add(i); System.out.println(bdq); System.out.println("Size of deque = "+bdq.size()); try { Thread.sleep(1000); bdq.addFirst(0); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Deque after adding element at the first position: "+bdq); System.out.println("Size of deque after adding element at the first position = "+bdq.size()); } } public class BdqAddLast { public static void main(String[] args) { BlockingDeque bdq = new LinkedBlockingDeque(); Runnable a = new AddLast(bdq); new Thread(a).start(); try{ Thread.sleep(2000); bdq.addLast(5); } catch(InterruptedException e){ } System.out.println("Deque after adding element at the last position: "+bdq); System.out.println("Size of deque after adding element at the last position = "+bdq.size()); } }