Java.til.concurren.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JDK5.0 -- Java.util.concurrent Roger Xia 2008-08 Concurrent Programming The built-in concurrency primitives -- wait(), notify(), synchronized, and volatile Hard to use correctly Specified at too low a level for most applications Can lead to poor performance if used incorrectly Too much wheel-reinventing! Let’s think about -- when do we need concurrency? -- how to do concurrent programming? -- concurrency strategy around us? ACID, Transaction, CAS -- lock, blocking, asynchronous task scheduling Questions? 如果要试图获取锁,但如果在给定的时间段内超时了还没有获得它,会发生什么情况?如果线程中断了,则放弃获取锁的尝试?创建一个至多可有 N 个线程持有的锁?支持多种方式的锁定(譬如带互斥写的并发读)?或者以一种方式来获取锁,但以另一种方式释放它?内置的锁定机制不直接支持上述这些情形,但可以在 Java 语言所提供的基本并发原语上构建它们。 Asynchronous task schedule new Thread(new Runnable() { ... } ).start(); Two drawback: 1. It is too much cost to create so many new threads to deal with a short task and then exit as JVM has to do much more work to allocate resources for thread creating and destroying. 2. How to avoid exhausting of resource when too much request at the same time? Thread pool how to effectively schedule task, deal with dead thread, limit tasks in queue (avoid server overload, how to deal with the overflow: discard the new task, old task or blocking the committing thread until queue is available) util.concurrent Doug Lea ? util.concurrent ? JSR-166 ? Tiger(java.util.concurrent) High quality, extensive use, concurrent open source package Exclusive lock, semaphore, blocking, thread safe collections Threads Pools and Task Scheduling Executors -- Framework for asynchronous execution Standardize asynchronous invocation Framework to execute Runnable and Callable tasks Separate submission from execution policy Use anExecutor.execute(aRunnable) Not new Thread(aRunnable).start() Cancellation and shutdown support Usually created via Executors factory class Configures flexible ThreadPoolExecutor Customize shutdown methods, before/after hooks, saturation policies, queuing Executor -- Decouple submission from execut

文档评论(0)

mv2323 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档