花了两天时间学习ConcurrentLinkedQueue 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.ConcurrentLinkedQueue;
import org.junit.Test;
/**
* ConcurrentLinkedQueue的测试类
*
* @date 2020-07-07 23:39:50
*/
public class ConcurrentLinkedQueueTest {
/**
* 无参构造函数head和tail初始化为node(null)
* @Param
*/
@Test
public void testConstruct0()throws Exception{
ConcurrentLinkedQueue testObj=new ConcurrentLinkedQueue();
System.out.println(testObj.toString());
}
/**
*通过集合初始化双向队列
* @Param
*/
@Test
public void testConstruct1()throws Exception{
Set set=new HashSet();
set.add(3);
ConcurrentLinkedQueue testObj=new ConcurrentLinkedQueue();
System.out.println(testObj.toString());
}
/**
*添加并返回boolean表示添加是否成功
* 和offer处理一样
* @Param
*/
@Test
public void testAdd()throws Exception{
ConcurrentLinkedQueue testObj=new ConcurrentLinkedQueue();
Sys