j.u.c: Java并发包的5大块

//TODO

Executors:

ExecutorService executor = Executors.newFixedThreadPool(10);
... newForkJoinPool()...

executor.submit (Callable<T> | Runnable)


1. 内置锁

2. Reentrant-Lock

3. Stamped-Lock

4. ReadWrite-Lock

 

Semaphore

锁是排他的、被锁住的code block 一次只能由唯一的线程在运行。 而Semaphore则可以提供指定数量的 permits, 允许最多指定数量的线程同时访问。

适用场景:

/**
* Whereas locks usually grant exclusive access to variables or resources,
* a semaphore is capable of maintaining whole sets of permits.
* This is useful in different scenarios where you have to limit the amount concurrent access
* to certain parts of your application.
*/


Atomic Variables
很简单的样子

Concurrent Collections (线程安全的容器)

 

posted on 2018-05-24 23:45  王家恒  阅读(168)  评论(0编辑  收藏  举报

导航