Java Concurrency In Practice - Chapter 1 Introduction
1.1. A (Very) Brief History of Concurrency
motivating factors for multiple programs to execute simultaneously:
Resource utilization. Programs sometimes have to wait for external operations such as input or output, and while waiting can do no useful work. It is more efficient to use that wait time to let another program run.
Fairness. Multiple users and programs may have equal claims on the machine's resources. It is preferable to let them
share the computer via finer‐grained time slicing than to let one program run to completion and then start another.
Convenience. It is often easier or more desirable to write several programs that each perform a single task and have
them coordinate with each other as necessary than to write a single program that performs all the tasks.
Threads allow multiple streams of program control flow to coexist within a process.
Each thread has its own program counter, stack, and local variables.
1.2. Benefits of Threads
- Reduce development and maintenance costs.
- Improve the performance of complex applications.
- Make it easier to model how humans work and interact, by turning asynchronous workflows into mostly sequential ones.
- In GUI applications for improving the responsiveness of the user interface.
- In server applications for improving resource utilization and throughput.
1.2.1. Exploiting Multiple Processors
As it gets harder to scale up clock rates, processor manufacturers will instead put more processor cores on a single chip.
1.2.2. Simplicity of Modeling
When you have only one type of task to do, you can start at the top of the pile and keep working until the pile is exhausted (or you are); you don't have to spend any mental energy figuring out what to work on next. On the other hand, managing multiple priorities and deadlines and switching from task to task usually carries some overhead.
1.2.3.Simplified Handling of Asynchronous Events
A server application that accepts socket connections from multiple remote clients may be easier to develop when each connection is allocated its own thread and allowed to use synchronous I/O.
1.2.4. More Responsive User Interfaces
The long running task is instead executed in a separate thread, the event thread remains free to process UI events, making the UI more responsive.
1.3 Risks of Threads
1.3.1 Safety Hazards
1.3.2. Liveness Hazards
A liveness failure occurs when an activity gets into a state such that it is permanently unable to make forward progress. One form of liveness failure that can occur in sequential programs is an inadvertent infinite loop, where the code that follows the loop never gets executed.
1.3.3. Performance Hazards
Performance issues subsume poor service time, responsiveness, throughput, resource consumption, or scalability.
Runtime overhead
- Context switches when the scheduler suspends the active thread temporarily so another thread can run.
- When threads share data, they must use synchronization mechanisms that can inhibit compiler optimizations, flush or invalidate memory caches, and create synchronization traffic on the shared memory bus.
1.4 Threads are Everywhere
JVM housekeeping tasks (garbage collection, finalization)
Frameworks introduce concurrency into applications by calling application components from framework threads. Components invariably access application state, thus requiring that all code paths accessing that state be thread-safe.
Timer, Servlet and JSPs, Remote Method Invocation(RMI) - RMI lets you invoke methods on objects running in another JVM.
A remote object must guard against two thread safety hazards: properly coordinating access to state that may be shared with other objects, and properly coordinating access to the state of the remote object itself (since the same object may be called in multiple threads simultaneously).
Java Concurrency In Practice - Chapter 1 Introduction的更多相关文章
- Java Concurrency In Practice -Chapter 2 Thread Safety
Writing thread-safe code is managing access to state and in particular to shared, mutable state. Obj ...
- Java Concurrency in Practice 读书笔记 第十章
粗略看完<Java Concurrency in Practice>这部书,确实是多线程/并发编程的一本好书.里面对各种并发的技术解释得比较透彻,虽然是面向Java的,但很多概念在其他语言 ...
- Java Concurrency In Practice
线程安全 定义 A class is thread-safe if it behaves correctly when accessed from multiple threads, regardle ...
- java并发编程实战(java concurrency in practice)
第一章 线程共享进程范围内的资源,但每个线程都有各自的程序计数器.栈以及局部变量等. 多个线程可以同时调度到多个CPU上运行. 线程的优势? 在服务应用程序中,可以提升资源利用率以及系统吞吐率 ...
- 读Java Concurrency in Practice. 第六章.
这一章开讲任务执行.绝大多数并发程序的工作都可以分解为抽象的.互不相关的工作单元,称之为任务(Task). 使用java线程来执行任务 以web服务器的实现举例, 此时将用户的一次连接,当做一个独立的 ...
- Java Concurrency in Practice——读书笔记
Thread Safety线程安全 线程安全编码的核心,就是管理对状态(state)的访问,尤其是对(共享shared.可变mutable)状态的访问. shared:指可以被多个线程访问的变量 mu ...
- Java Concurrency in Practice 读书笔记 第二章
第二章的思维导图(代码迟点补上):
- java concurrency in practice读书笔记---ThreadLocal原理
ThreadLocal这个类很强大,用处十分广泛,可以解决多线程之间共享变量问题,那么ThreadLocal的原理是什么样呢?源代码最能说明问题! public class ThreadLocal&l ...
- 深入浅出 Java Concurrency (4): 原子操作 part 3 指令重排序与happens-before法则
转: http://www.blogjava.net/xylz/archive/2010/07/03/325168.html 在这个小结里面重点讨论原子操作的原理和设计思想. 由于在下一个章节中会谈到 ...
随机推荐
- Mysql的NULL的一个注意点
今天看到一个问题: select a.* from a where (a.id not in (NULL)); 这个sql语句会返回什么? 刚开始以为是返回所有item,但是实际运行下返回是返回emp ...
- 谈HTTP的KeepAlive
为什么要使用KeepAlive? 终极的原因就是需要加快客户端和服务端的访问请求速度.KeepAlive就是浏览器和服务端之间保持长连接,这个连接是可以复用的.当客户端发送一次请求,收到相应以后,第二 ...
- python反转字符串(简单方法)及简单的文件操作示例
Python反转字符串的最简单方法是用切片: >>> a=' >>> print a[::-1] 654321 切片介绍:切片操作符中的第一个数(冒号之前)表示切片 ...
- 从P6 EPPM 8 R3 到P6 EPPM 16 R1 有哪些改变?
Product 特征 First Release for Feature P6 EPPM 通过编辑活动标识替换关系.当你需要修改一个关系,你不需要删除现有的关系,并作出一个新的,你可以简单地编辑活动的 ...
- Silverlight开源项目与第三方控件收集
http://easysl.codeplex.com/ http://compositewpf.codeplex.com/ http://silverlight.codeplex.com/releas ...
- 常用vs快捷键
Ctrl+E,D ----格式化全部代码 Ctrl+A+K+FCtrl+E,F ----格式化选中的代码 Ctrl+K+FCTRL + SHIFT + B生成解决方案 Alt+B+B 或 F6 生成当 ...
- 互联网产品团队中Web前端工程师的重要性
国内外各大互联网公司,都有UEx/d|UCD|CDC(Customer Research & User Experience Design Center)团队. 在很多公司会认为,合格的产品经 ...
- AC自动机---Keywords Search
题目网址:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=110773#problem/A Description In the moder ...
- IBATIS动态SQL(转)
直接使用JDBC一个非常普遍的问题就是动态SQL.使用参数值.参数本身和数据列都是动态SQL,通常是非常困难的.典型的解决办法就是用上一堆的IF-ELSE条件语句和一连串的字符串连接.对于这个问题,I ...
- jquery 拓展
1. 概述 jquery允许拓展自定义的方法, 绑定到$.fn对象上, 编写一个jQuery插件的原则: 给$.fn绑定函数,实现插件的代码逻辑: 插件函数最后要return this;以支持链式调用 ...