c语言sscanf函数的用法是什么
263
2022-11-18
BlockingQueue_阻塞队列_juc
BlockingQueue
LinkedBlockingQueue,ArrayBlockingQueue
Queue: Deque,AbstractQueue,BlockingQueue
加入和移除
1抛出异常的情况
@Test public void test1(){ ArrayBlockingQueue arr = new ArrayBlockingQueue<>(1); System.out.println(arr.add("A"));// System.out.println(arr.add("B")); //报错 System.out.println(arr.remove());// System.out.println(arr.remove()); //报错 }
2.不抛出异常的情况
@Test public void test2(){ ArrayBlockingQueue arr = new ArrayBlockingQueue<>(1); System.out.println(arr.offer("A")); System.out.println(arr.offer("A"));//false System.out.println(arr.poll()); System.out.println(arr.poll());//null }
3.阻塞等待
不满足的话就一直阻塞
@Test public void test3() throws InterruptedException { ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(1); //一直阻塞 arrayBlockingQueue.put("A"); arrayBlockingQueue.put("B"); System.out.println(arrayBlockingQueue.take()); System.out.println(arrayBlockingQueue.take()); }
4.超时等待
@Test public void test4() throws InterruptedException { ArrayBlockingQueue arrayBlockingQueue = new ArrayBlockingQueue(1); arrayBlockingQueue.offer("A"); arrayBlockingQueue.offer("B",2, TimeUnit.SECONDS); }
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~