Java多线程设计模式

副标题:无

作   者:[日]结城浩著;博硕文化译

分类号:

ISBN:9787113064020

微信扫一扫,移动浏览光盘

简介

多线程与并发处理是程序设计好坏优劣的重要课题,本书通过浅显易懂的文字与实例来介绍JAVA线程相关的设计模式概念,并且通过实际的JAVA程序范例和UML图示来一一解说,书中有代码的重要部分加上标注使读者更加容易解读,再配合众多的说明图解,无论对于初学者还是程序设计高手来说,这都是一本学习和认识设计模式非常难得的好书。 书中包含JAVA线程的介绍导读,12个重要的线程设计模式和全书总结以及丰富的附录内容。每一章相关线程设计模式的介绍,都举一反三使读者学习更有笑率。最后附上练习问题,让读者可以温故而知新,能快速地吸收书中的精华,书中最后附上练习问题解答,方便读者学习验证。

目录

漫谈uml

uml

类图

类和层次结构的关系

接口与实现

聚合

访问控制

类间的关联性

顺序图

处理流程和对象间的协调

时序图

introduction 1 java语言的线程

java语言的线程

何谓线程

明为追踪处理流程,实则追踪线程

单线程程序

多线程程序

thread类的run方法和start方法

线程的启动

线程的启动(1)——利用thread类的子类

.线程的启动(2)——利用runnable接口

线程的暂时停止

线程的共享互斥

synchronized方法

synchronized阻挡

线程的协调

wait set——线程的休息室

wait方法——把线程放入wait set

notif3,方法——从wait set拿出线程

notifyall方法——从wait set拿出所有线程

wait、notify、notifyall是object类的方法

线程的状态移转

跟线程有关的其他话题

重点回顾

练习问题

introduction 2 多线程程序的评量标准

多线程程序的评量标准

安全性——不损坏对象

生存性——进行必要的处理

复用性——可再利用类

性能——能快速、大量进行处理

评量标准的总结

重点回顾

练习问题

第1章 single threaded execution——能通过这座桥的,只有一个人

single threaded execution pattern

范例程序1:不使用single threaded execution pattern的范例

main类

并非线程安全(thread-safe)的gate类

userthread类

执行看看·果然出错了

为什么会出错呢

范例程序2:使用single threaded execution pattern的范例

线程安全的gate类

synchronized所扮演的角色

single threaded execution pattern的所有参与者

扩展思考方向的提示

何时使用(适用性)

生命性与死锁

可重用性与继承异常

临界区的大小与执行性能

相关pattern

guarded suspension pattern(第3章)

read-write lock pattern(第6章)

immutable pattern(第2章)

thread-specific storage pattern(第11章)

进阶说明:关于synchronized

synchronized语法与before/after pattern

这个synchronized在保护什么

该以什么单位来保护呢

获取谁的锁定来保护的呢

原子的操作

long与double并不是原子的

重点回顾

练习问题

第2章 immutable——想破坏它也没办法

immutable pattern

范例程序

使用immutable pattern的person类

main类

printpersonthread类

immutable pattern的所有参与者

扩展思考方向的提示

何时使用(适用性)

思考成对的mutable类与immutable类[执行性能]

为了保护类的不变性[复用性]

标准类链接库里使用到的immutable pattern

相关pattern

single threaded execution pattern(第l章)

read-write lock pattern(第6章)

flyweight pattern(参考附录e[gof][yuki01])

进阶说明:final

重点回顾

练习问题

第3章 guarded suspension——要等到我准备好喔

guarded suspension pattern

范例程序

request类

requestqueue类

clientthread类

serverthread类

main类

java.util.linkedlist类的操作

仔细分析getrequest方法

仔细分析putrequest方法

synchronized的意义

wait与锁定

guarded suspension pattern的所有参与者

扩展思考方向的提示

有条件的synchronized

多线程版的if

忘记更改状态与生命性

wait与notif3,/notif3,all的责任[复用性]

各种各样的称呼

相关pattern

single threaded execution paaem(第1章)

balking pattern(第4章)

producer-consumer pattern(第5章)

future pattern(第9章)

重点回顾

练习问题

第4章 balking——不需要的话,就算了吧

balking pattern

范例程序

data类

saverthread类

changerthread类

main类

balking pattern的所有参与者

扩展思考方向的提示

何时使用(适用性)

表达balk结果的方式

相关paaem

guarded suspension pattern(第3章)

observer pattern(参考附录e[gof][yuki01])

进阶说明:timeout

b alking parem与guarded suspension pattern的中间

wait的结束是什么时候

guarded timed的实现

synchronized没有timeout,也不能中断

重点回顾

练习问题

第5章 producer-consumer——我来做,你来用

producer-consumer pattern

范例程序

main类

makerthread类

eaterthread类

table类

分析put方法

分析take方法

producer-consumer pattern的所有参与者

扩展思考方向的提示

保护安全性的channel参与者[复用性]

不能直接传递吗

channel参与者负荷派生的问题

要以什么顺序传递data参与者

[中间者的存在]隐含的意义

只有一个consumer参与者时会如何

相关parem

mediator parern(参考附录e[gof][yukiol])

worker thread pattern(第8章)

command pattern(参考附录e[gof][yuki01])

strategy pattern(参考附录e[gof][yuki01])

进阶说明:interruptedexception异常

可能会花一些时间,但是可以取消掉

后面接着throws interruptedexception的方法

sleep方法与interrupt方法

wait方法与interrupt方法

ioin方法与interrupt方法

interrupt方法只是改变中断状态而已

isinterrupted方法——检查中断状态

thread.interrupted方法——检查并清除中断状态

thread类的stop方法不能使用

重点回顾

练习问题

第6章 read-write lock——大家想看就看吧,不过看的时候不能写喔.

read-write lock pattern

范例程序

main类

data类

writerthread类

readerthread类

readwritelock类

执行结果

检验警戒条件

read-write lock pattern的所有参与者

扩展思考方向的提示

利用同时“读取"不会冲突的特性,提高程序的性能

适合读取操作繁重时

适合读取比写入次数频繁时

锁定的意义

相关pattern

immutable pattern(第2章)。

single threaded execution pattern(第1章)

guarded suspension pattern(第3章)

before/after pattern(参考附录e[lea])

strategized locking pattern(参考附录e[posa2])

重点回顾

练习问题

第7章 thread·per-message——这个工作交给你了

thread-per-message pattern

范例程序

main类

host类

helper类

thread-per-message pattern的所有参与者一

扩展思考方向的提示

提升响应性,降低延迟时间

适合在操作顺序无所谓时使用

不需要返回值的时候

应用在服务器的制作

调用方法+启动线程一传送消息

相关pattern

future pattern(第9章)

worker thread pattern(第8章)

进阶说明:进程与线程

重点回顾

练习问题

第8章 worker thread——等到工作来,来了就工作

worker thread parern

范例程序

main类

clientthread类

request类

channel类

workerthread类

worker thread paaern的所有参与者

扩展思考方向的提示

启动线程是繁重的操作

控制承载量

invocation与execution的分离

runnable接口的意义

多态的request参与者

只有一条worker参与者

相关pattern

producer-consumer pattern(第5章)

thread-per-message pattern(第7章)

command pattern(参考附录e[gof][yuki01])

future pattern(第9章)

flyweight pattern(参考附录e[gof][yukiol])

thread-specific storage pattern(第11章)

active obiect pattern(第12章)

进阶说明:swing的event-dispatching thread

何谓event-dispatching thread

event-dispatching thread只有一条

event-dispatching thread会调用listener

注册listener的意义

event-dispatching thread也处理画面的重绘

javax.swing.swingutilities类

swing的单线程规则

重点回顾

练习问题

第9章 future——先给您这张提货单

future pattern

范例程序

main类

host类

data接口

futuredata类

realdata类

future pattern的所有参与者

扩展思考方向的提示

能够提升throughput吗

异步方法调用的“返回值”

分离“准备返回值”与“使用返回值”

变形——不让人等待的future参与者

变形——会改变的future参与者

谁需要考虑到多线程[复用性]

回调与future pattern

相关pattern

thread-per-message parem(第7章)

builder pattern(参考附录e[gof][yuki01])

proxy pattern(参考附录e[gof][yuki01])

guarded suspension pattem(第3章)

重点回顾

thread-specific storage pattern(第11章)

active obiect pattern(第12章)

进阶说明:swing的event-dispatching thread

何谓event-dispatching thread

event-dispatching thread只有一条

event-dispatching thread会调用listener

注册listener的意义

event-dispatching thread也处理画面的重绘

javax.swing.swingutilities类

swing的单线程规则

重点回顾

练习问题

练习问题

第10章 two-phase termination——快把玩具收拾好,去睡觉吧

two-phase termination pattern

范例程序

countupthread类

main类

two-phase termination patt.em的所有参与者

扩展思考方向的提示

不可以使用thread类的stop方法

只检查标识是不够周全的

只测试中断状态也是不够的

进行繁重的处理前,先检查终止请求

join方法与isalive方法

程序的结束与addshutdownhook方法

优雅终止的线程

相关pattern

before/after pattern(参考附录e[lea])

multiphase cancellation pattern(参考附录e[lea])

multi-phase startup pattern

balking pattern(第4章)

进阶说明: 中断状态与interruptedexception异常的相互转换

中断状态一interruptedexception异常的转换

interruptedexception异常一转换为中断状态

interruptedexception异常一转换为interruptedexception异常

重点回顾

练习问题

第11章 thread·specific storage——每个线程的保管箱

thread-specific storage pattern.

关于java.1ang.threadlocal类

java.1ang.threadlocal是保管箱间

范例程序1:没有使用thread-specific storage pattern的范例

log类

main类

范例程序2:使用thread-specific storage parem的范例

线程特有的tslog类

log类

clientthread类

main类

thread-specific storage pattern的所有参与者

扩展思考方向的提示

局部变量与java.1ang.threadlocal类

放置线程特有信息的地方

不必担心被其他线程访问

throughput的提升取决于实现

隐藏context的危险性

相关pattern

singleton pattern(参考附录e[gof][yuki01])

worker thread pattern(第8章)

single threaded execution pattern(第1章)

proxy pattern(参考附录e[gof][yuki01])

进阶说明:actor-based与task-based

主体与客体

actor-based的思维

task-based的思维

实际上两个开发方式是混用的

重点回顾

练习问题

第12章 active object——接受异步消息的主动对象

active object pattern

范例程序

使用端:main类

使用端:makerclientthread类

使用端:displayclientthread类

“主动对象”端:activeobject接口

“主动对象”端:activeobjectfactory类

“主动对象”端:proxy类

“主动对象”端:schedulerthread类

“主动对象”端:activationqueue类

“主动对象”端:methodrequest类

“主动对象”端:makestringrequest类

“主动对象”端:displaystringrequest类

“主动对象”端:result类

“主动对象”端:futureresult类

“主动对象”端:realresult类

“主动对象”端:servant类

执行范例程序

active obiect pattern的所有参与者

扩展思考方向的提示

到底做了什么事呢

parem是否适合使用要考虑问题的规模

注意并发性

新增方法

scheduler参与者的角色

“主动对象”之间的对话

迈向分布处理——将线程的界限移到机器的界限

相关pattern

producer-consumer pattern(第5章)

future pattern(第9章)

worker thread pattern(第8章)

thread-specific storage pattern(第11章)

重点回顾

练习问题

总结 多线程程序设计的模式语言

多线程程序设计的模式语言

pattern与pattern language

single threaded execution pattern(第1章)——能通过这座桥的,只有一个人

immutable pattern(第2章)——想破坏它也没办法

guarded suspension pattern(第3章)——等到我准备好

balking pattern(第4章)——不需要的话,就算了吧

producer-consumer pattern(第5章)——你来做,我来用

read-write lock pattem(第6章)——大家想看就看吧,不过看的时候不能写喔

thread-per-message pattern(第7章)——这个工作交给你了

worker thread pattern(第8章)——等到工作来,来了就工作

future pattern(第9章)——先给您这张提货单

two-phase termination pattern(第10章)——快把玩具收拾好,去睡觉吧

thread-specific storage pattem(第11章)——每个线程的保管箱

active object pattern(第12章)——接受异步消息的主动对象

尾声

附录a 练习问题的解答

附录b java的内存模型

附录c java线程的优先级

附录d 线程相关的主要api

附录e 参考文献

已确认勘误

次印刷

页码 勘误内容 提交人 修订印次

Java多线程设计模式
    • 名称
    • 类型
    • 大小

    光盘服务联系方式: 020-38250260    客服QQ:4006604884

    意见反馈

    14:15

    关闭

    云图客服:

    尊敬的用户,您好!您有任何提议或者建议都可以在此提出来,我们会谦虚地接受任何意见。

    或者您是想咨询:

    用户发送的提问,这种方式就需要有位在线客服来回答用户的问题,这种 就属于对话式的,问题是这种提问是否需要用户登录才能提问

    Video Player
    ×
    Audio Player
    ×
    pdf Player
    ×
    Current View

    看过该图书的还喜欢

    some pictures

    解忧杂货店

    东野圭吾 (作者), 李盈春 (译者)

    loading icon