码迷,mamicode.com
首页 > 其他好文 > 详细

j.u.c :: Executor, Runnable vs Callable | Locks, Atomic Varibles, CocurrentCollections

时间:2019-01-25 01:07:24      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:map   sem   variables   var   简单   call   callable   nbsp   ant   

//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

标签:map   sem   variables   var   简单   call   callable   nbsp   ant   

原文地址:https://www.cnblogs.com/nanlan2017/p/10317609.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!