j.u.c :: Executor, Runnable vs Callable | Locks, Atomic Varibles, CocurrentCollections
Posted nanlan2017
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了j.u.c :: Executor, Runnable vs Callable | Locks, Atomic Varibles, CocurrentCollections相关的知识,希望对你有一定的参考价值。
//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 (线程安全的容器)
以上是关于j.u.c :: Executor, Runnable vs Callable | Locks, Atomic Varibles, CocurrentCollections的主要内容,如果未能解决你的问题,请参考以下文章