今天时间学习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