传统线程技术:
提一点ThreadLocal的使用
java.util.concurrent包技术:
1. java.util.concurrent.atomic.* 原子性类的使用
2. java.util.concurrent.ExecutorService 线程池的使用
3. Future和Callable Callable有返回结果的线程,返回结果的包装类Future
4. 一组Callable和一组Future的使用情况
ExecutorService ts = Executors.newSingleThreadExecutor();
CompletionService<String> cs = new ExecutorCompletionService<String>(ts);
5. java.util.concurrent.locks.Lock; 锁的使用,读写锁
6. java.util.concurrent.CyclicBarrier; 临界点的使用
CyclicBarrier cyclicBarrier = new CyclicBarrier(8);
cyclicBarrier.await();
7. CountDownLatch 解释说明
CountDownLatch,一个同步辅助类,在完成一组正在其他线程中执行的操作之前,它允许一个或多个线程一直等待。
主要方法
public CountDownLatch(int count);
public void countDown();
public void await() throws InterruptedException
构造方法参数指定了计数的次数
countDown方法,当前线程调用此方法,则计数减一
awaint方法,调用此方法会一直阻塞当前线程,直到计时器的值为0
CountDownLatch 是一次性使用的,也就是说latch门闩只能只用一次,一旦latch门闩被打开就不能再次关闭
8. Exchanger的用法 交换数据
9. ConcurrentHashMap和BlockingQueue 同步集合和阻塞队列的使用