Android-ThreadPoolExecutor
来源:互联网 发布:mac切换页面快捷键 编辑:程序博客网 时间:2024/06/06 12:46
ReentrantLock(互斥锁,和synchronized一样,但是具备更多的扩展功能):
class X { private final ReentrantLock lock = new ReentrantLock(); // ... public void m() { lock.lock(); // block until condition holds try { // ... method body finally { lock.unlock() } } }}
Condition(是一个接口,一般和锁连用)
假设我们有一个bounded buffer,支持put和take,那么当已经put full的时候,这个时候就等待;take empty的时候,这个时候也等待,可以这样实现:
class BoundedBuffer { final Lock lock = new ReentrantLock(); final Condition notFull = lock.newCondition(); final Condition notEmpty = lock.newCondition(); final Object[] items = new Object[100]; int putptr, takeptr, count; public void put(Object x) throws InterruptedException { lock.lock(); try { while (count == items.length) notFull.await(); items[putptr] = x; if (++putptr == items.length) putptr = 0; ++count; notEmpty.signal(); } finally { lock.unlock(); } } public Object take() throws InterruptedException { lock.lock(); try { while (count == 0) notEmpty.await(); Object x = items[takeptr]; if (++takeptr == items.length) takeptr = 0; --count; notFull.signal(); return x; } finally { lock.unlock(); } } }
0 0
- Android-ThreadPoolExecutor
- Android API : ThreadPoolExecutor
- Android 多线程 ThreadPoolExecutor
- Android 线程池 ThreadPoolExecutor
- Android之ThreadPoolExecutor
- android线程池--ThreadPoolExecutor
- Android--ThreadPoolExecutor线程池
- android 线程池 ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- android 线程池对象-ThreadPoolExecutor
- Android ThreadPoolExecutor 的参数详解
- Android线程池ThreadPoolExecutor详解
- Android中的线程池ThreadPoolExecutor
- Android之ThreadPoolExecutor源码分析
- Android中的线程池ThreadPoolExecutor
- ThreadPoolExecutor
- win8 安装程序时出现2502 2503错误解决方法
- Mockups
- 解决union all 联合查询,速度慢的问题
- kthread_work和kthread_worker机制
- 友链SEO工具:换链神器测试体验
- Android-ThreadPoolExecutor
- RabbitMQ (二) 命令初尝
- Binder结点死亡通知过程
- 初探FFT在数字图像处理中的应用(fft2函数的使用方法)
- 用Fiddler模拟低速网络环境
- oralce 查看是否启动 登陆 创建用户 常用命令小记
- HDU 5055 - Bob and math problem(贪心)
- 未名
- I Think I Need a Houseboat(水题)