标签:
这是迅雷的一道面试题,顺序打印ABC十次。
public class TenABC { public static void main(String[] args) { final BlockingQueue queue = new ArrayBlockingQueue(30); for (int i = 0; i < 10; i++) { try { queue.put("A"); queue.put("B"); queue.put("C"); } catch (InterruptedException e) { e.printStackTrace(); } } new Thread(new Runnable() { @Override public void run() { boolean flag =true; while(flag){ if(queue.size()!=0){ try { System.out.print(queue.take()); } catch (InterruptedException e) { e.printStackTrace(); } } else{ flag=false; } } } }).start(); } }
标签:
原文地址:http://blog.csdn.net/liyantianmin/article/details/42848265