多线程并发主要有3个方面:
1、同步器
主要有synchronized,ReentrantLock(),信号量,门栓(CountDownLatch),障栅(CyclicBarrier),交换器。
2、同步容器:
主要包括:映射、集、队列
映射:ConcurrentHashMap,ConcurrentSkipListMap(有序,要求键实现Comparable)
集:ConcurrentSkipListSet(有序,要求键要实现Comparable)
队列:ConcurrentLinkedQueue(无界队列),ConcurrentArrayQueue(有界队列)
BlockingQueue(阻塞队列,线程池中大量使用)
3、线程池
Excecuter 接口,有一个sumbit方法,提交任务,并执行
ExcecutorService,执行器服务,用于执行smbit
Excecutors: 工具类,里面有很多静态方法。(参考集合的Collections工具类) ,主要用具创建缓存线程池(newCachedThreadPool)、单线程池(newSingleTreadExcecutor)、固定数量的线程池(newFixedThreadPool)、定时执行线程池(newScheduledThreadPool)
ThreadPoolExecutor:线程池,将没有来得及执行线程放在队列中,空闲的线程从队列中取得任务执行。