标签:
1.LinkedBlockingDeque
public class LinkedBlockingDeque<E> extends AbstractQueue<E> implements BlockingDeque<E>, Serializable
2.主要方法
public class Client implements Runnable { private LinkedBlockingDeque<String> requestList; public Client(LinkedBlockingDeque<String> requestList) { super(); this.requestList = requestList; } @Override public void run() { for (int i = 0; i < 3; i++) { for (int j = 0; j < 5; j++) { StringBuilder request = new StringBuilder(); request.append(i); request.append(":"); request.append(j); try { requestList.put(request.toString()); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Clint: " + request + " " + new Date()); } try { TimeUnit.SECONDS.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); } } System.out.println("Client: End"); } }
public class LinkedBlockingDequeMain { public static void main(String[] args) throws Exception { LinkedBlockingDeque<String> list=new LinkedBlockingDeque<String>(3); Client client=new Client(list); Thread thread=new Thread(client); thread.start(); for (int i = 0; i <5; i++) { for (int j =0; j <3; j++) { String request=list.take(); System.out.println("Main:Request:"+request+" at "+new Date()+" Size "+list.size()); } TimeUnit.MILLISECONDS.sleep(300); } System.out.println("Main:End"); } }
标签:
原文地址:http://www.cnblogs.com/wxgblogs/p/5464586.html