Learn from Synchronized and BlockingQueue
来源:互联网 发布:知乎 万历郑贵妃 编辑:程序博客网 时间:2024/06/06 01:56
The producer and consumer model:
Object has a value that intent to be produced by producer and consumed by consumer.
Object also has produce method which used byProducer and consume method which used by Consumer.
usage of BlockingQueue in the producer-consumer model:
http://www.java3z.com/cwbwebhome/article/article20/200030.html?id=4852
Because thread.stop() is unsafe, so we should avoid the use of it.
Instead, we use ExecutorService.submit() and ExecutorService.shutdownNow()
</pre><pre name="code" class="html">Basket basket = new Basket();Runnable producer = new Producer(basket);Runnable consumer = new Consumer(basket);ExecutorService service = Executors.newCachedThreadPool();service.submit(producer);service.submit(consumer);try {<span style="white-space:pre"></span>Therad.sleep(7000);} catch (InterruptedException e) {<span style="white-space:pre"></span>e.printStackTrace();}service.shutdownNow();}
0 0
- Learn from Synchronized and BlockingQueue
- WWDC-Watch and learn from our Engineers
- 线程通信synchronized、clock、Blockingqueue
- Learn From LaMothe
- Learn from AWS outage
- learn from Mobimsg
- OpenGL learn from today
- Learn English From Linux
- Learn From Code--Kaggle
- Learn from vimtutor
- Concurrency and multi-thread learn from Cloud Computer Individual Project 3.2
- Java - Why wait notify and notifyAll called from synchronized block or method in Java
- Learn From Real Coding (1)
- Learn Arm11 From Scratch(一)
- Learn Arm11 From Scratch(二)
- Learn from Architects of Buildings
- Learn git from code school
- java并发之BlockingQueue和Lock以及synchronized
- [LeetCode] Basic Calculator
- 打印字符串所有的子集
- C语言第十章:结构体、枚举、预处理指令
- Android学习res资源文件
- C语言第十一章:文件
- Learn from Synchronized and BlockingQueue
- npm ERR!无法安装任何包的解决办法
- 指向二维数组的指针
- Hadoop应用-------Hadoop计算能力调度器(Capacity Scheduler)应用和配置{hadoop mradmin -refreshQueues动态更新队列和容量}其他调度器比较
- Android Fragment生命周期深入探究
- Hadoop应用------如何编写Hadoop调度器【可以先学习雅虎开源的容量调度器和facebook开源的公平调度器】
- iOS常用小功能集锦
- 协同过滤推荐及相似性度量
- vmware安装CentOS " Intel VT-x 处于禁用状态"