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

  1. Reduce development and maintenance costs.
  2. Improve the performance of complex applications.
  3. Make it easier to model how humans work and interact, by turning asynchronous workflows into mostly sequential ones.
  4. In GUI applications for improving the responsiveness of the user interface.
  5. 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

  1. Context switches when the scheduler suspends the active thread temporarily so another thread can run.
  2. 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的更多相关文章

  1. 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 ...

  2. Java Concurrency in Practice 读书笔记 第十章

    粗略看完<Java Concurrency in Practice>这部书,确实是多线程/并发编程的一本好书.里面对各种并发的技术解释得比较透彻,虽然是面向Java的,但很多概念在其他语言 ...

  3. Java Concurrency In Practice

    线程安全 定义 A class is thread-safe if it behaves correctly when accessed from multiple threads, regardle ...

  4. java并发编程实战(java concurrency in practice)

    第一章   线程共享进程范围内的资源,但每个线程都有各自的程序计数器.栈以及局部变量等. 多个线程可以同时调度到多个CPU上运行.   线程的优势? 在服务应用程序中,可以提升资源利用率以及系统吞吐率 ...

  5. 读Java Concurrency in Practice. 第六章.

    这一章开讲任务执行.绝大多数并发程序的工作都可以分解为抽象的.互不相关的工作单元,称之为任务(Task). 使用java线程来执行任务 以web服务器的实现举例, 此时将用户的一次连接,当做一个独立的 ...

  6. Java Concurrency in Practice——读书笔记

    Thread Safety线程安全 线程安全编码的核心,就是管理对状态(state)的访问,尤其是对(共享shared.可变mutable)状态的访问. shared:指可以被多个线程访问的变量 mu ...

  7. Java Concurrency in Practice 读书笔记 第二章

    第二章的思维导图(代码迟点补上):

  8. java concurrency in practice读书笔记---ThreadLocal原理

    ThreadLocal这个类很强大,用处十分广泛,可以解决多线程之间共享变量问题,那么ThreadLocal的原理是什么样呢?源代码最能说明问题! public class ThreadLocal&l ...

  9. 深入浅出 Java Concurrency (4): 原子操作 part 3 指令重排序与happens-before法则

    转: http://www.blogjava.net/xylz/archive/2010/07/03/325168.html 在这个小结里面重点讨论原子操作的原理和设计思想. 由于在下一个章节中会谈到 ...

随机推荐

  1. 参数嗅探(Parameter Sniffing)(2/2)

    在参数嗅探(Parameter Sniffing)(1/2)里,我介绍了SQL Server里参数嗅探的基本概念和背后的问题.如你所见,当缓存的计划被SQL Server盲目重用时,会带来严重的性能问 ...

  2. EFcodeFirst+T4=操纵任意数据库

    之前有写过两篇,EF选择Mysql数据源 跟 EF添加ADO.NET实体模型处直接选择Oracle数据源,其方便之处就不多说了,使用DBfirst直接点点点就能与数据库双向更新,而且关键是方便我们使用 ...

  3. IntelliJ IDEA 的SVN配置与使用

    SVN 首先提一句,IDEA对各种的版本控制工具的支持是非常好的,点击3 打开系统设置界面,就可以看到他有专门的一栏 Version Control 里边是对各种版本控制工具的支持,其中我要用的SVN ...

  4. .net C# 对虚拟目录IIS的操作

    一.查看虚拟目录是否存在 private bool IsExitesVirtualDir(string virtualdirname) {    bool exited =false;    Dire ...

  5. 2016年5月11日摘自知乎的一些Redis大概了解

    1. 知乎日报的基础数据和统计信息是用 Redis 存储的,这使得请求的平均响应时间能在 10ms 以下.其他数据仍然需要存放在另外的地方,其实完全用 Redis 也是可行的,主要的考量是内存占用.就 ...

  6. JMS学习(三)JMS 消息结构之属性及消息体详解

    一.前言 通过上一篇的学习我们知道了消息分为三个部分,即消息头,属性及消息体,并对消息头的十个属性进行了详细的介绍,本文再对消息属性及消息体进行详细的介绍. 二.属性介绍 消息属性的主要作用是可以对头 ...

  7. [moka同学笔记]一、Yii2.0课程笔记(魏曦老师教程)

    第一节   第二节             课程内容     

  8. 推荐轻量友好的.NET测试断言工具Shouldly

    Shouldly是一个轻量的断言(Assertion)框架,用于补充.NET框架下的测试工具.Shouldly将焦点放在当断言失败时如何简单精准的给出很好的错误信息. Shouldly在GitHub的 ...

  9. 基于java的socket编程

    #开头的废话#学习java已经半个月了,原本在抠教材里面的字眼时,觉得教材好厚,要看完不知道要到猴年马月去了.突然在网上看到一个教程,里面老师说学编程语言书不用太细看,看个大概,知道里面讲些什么就好, ...

  10. ASP.NET Web API默认支持的媒体类型(SupportedMediaTypes)

    JsonMediaTypeFormatter XmlMediaTypeFormatter ( application/xml  text/xml) FormUrlEncodedMediaTypeFor ...