今天时间学习CyclicBarrier api,该类是JUC原子包中的类,通过单元测试代码把所有public api方法跑了一遍,大致了解了底层实现,初学乍练,有很多一知半解的地方,待后续有了深入理解再来补充
package test.java.util.concurrent;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.*;
import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
import org.junit.Test;
/**
* ForkJoinPool的测试类
*
* @date 2020-07-19 14:18:13
*/
public class ForkJoinPoolTest {
/**
* 使用默认参数初始化线程池
* java.util.concurrent.ForkJoinPool@14514713
* [Running, parallelism = 8, size = 0, active = 0, running = 0, steals = 0, tasks = 0, submissions = 0]
* @Param
*/
@Test
public void testConstruct0()throws Exception{
ForkJoinPool testObj=new ForkJoinPool();
System.out.println(testObj);
}
/**
* 通过制定并发数参数初始化线程池
* @Param
*/
@Test
public void testConstruct1()throws Exception{
ForkJoinPool testObj=new ForkJoinPool(11);
System.out.println(testObj);
}
/**
* 通过并发数,默认线程创建工厂,异常处理器初始化线程池
* @Param
*/
@Test
public void testConstruct2()throws Exception{
ForkJoinPool testObj=new ForkJoinPool(33,ForkJoinPool.defaultForkJoinWorkerThreadFactory,new ThreadGroup("forkJoin"),false );
System.out.println(testObj);
}
/**
* 获取默认static代码块初始化的线程池
* @Param
*/
@Test
public void testCommonPool()throws Exception{
ForkJoinPool pool=ForkJoinPool.commonPool();
pool.submit(()-> System.out.println(2222));
}
/**
* 执行制定forkJoinTask
* @Param
*/
@Test
public void testInvoke()throws Exception{
ForkJoinPool pool=ForkJoinPool.commonPool();
pool.invoke(ForkJoinTask.adapt(()-> System.out.println(2333)));
}
/**
* 执行ForkJoinTask
* @Param