LinkedBlockingQueue api 详解

本文通过单元测试详细探讨了Java JUC中的LinkedBlockingQueue API,覆盖所有公共方法,初步理解其底层实现。尽管目前理解尚不全面,未来将逐步深化学习并补充相关内容。
摘要由CSDN通过智能技术生成

今天时间学习LinkedBlockingQueue api,该类是JUC原子包中的类,通过单元测试代码把所有public api方法跑了一遍,大致了解了底层实现,初学乍练,有很多一知半解的地方,待后续有了深入理解再来补充

package test.java.util.concurrent;


import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.Spliterator;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

import org.junit.Test;

/**
 * LinkedBlockingQueue的测试类
 *
 * @date 2020-07-26 20:44:58
 */
public class LinkedBlockingQueueTest {
        /**
        *无参构造函数
        * @Param
        */
        @Test
        public void testConstruct0()throws Exception{
        LinkedBlockingQueue testObj=new LinkedBlockingQueue();
                System.out.println(testObj.toString());
        }
        /**
        * 初始化固定大小的队列
        * @Param
        */
        @Test
        public void testConstruct1()throws Exception{
        LinkedBlockingQueue testObj=new LinkedBlockingQueue(3);
                System.out.println(testObj.toString());
        }
        /**
        *  通过集合初始化阻塞队列
        * @Param
        */
        @Test
        public void testConstruct2()throws Exception{
                Set<String> set=new HashSet<>();
                set.add("32");
                LinkedBlockingQueue testObj=new LinkedBlockingQueue(set);
                System.out.println(testObj.poll());
                System.out.println(testObj.poll());
        }
        /**
         * 查看队列大小
         * @Param
         */
        @Test
        public void testSize()throws Exception{
                LinkedBlockingQueue testObj=new LinkedBlockingQueue();
                System.out.println(testObj.size());
        }
        /**
         * 查看队列剩余容量
         * @Param
         */
        @Test
        public void testRemainingCapacity()throws Exception{
                LinkedBlockingQueue testObj=n
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值