在好例子网,分享、交流、成长!
您当前所在位置:首页Java 开发实例常规Java编程 → Java性能权威指南.pdf

Java性能权威指南.pdf

常规Java编程

下载此实例
  • 开发语言:Java
  • 实例大小:9.36M
  • 下载次数:7
  • 浏览次数:23
  • 发布时间:2021-02-18
  • 实例类别:常规Java编程
  • 发 布 人:regedit0726
  • 所需积分:2
 相关标签: java 权威指南 指南

实例介绍

【实例简介】

【实例截图】

from clipboard

【核心代码】

目录
推荐序 .....................................................................................................................................................xi
前言.........................................................................................................................................................xii
第 1 章 导论 .........................................................................................................................................1
1.1 概述 .............................................................................................................................................2
1.2 平台版本约定 .............................................................................................................................2
1.3 全面的性能调优 .........................................................................................................................4
1.3.1 编写更好的算法 ............................................................................................................4
1.3.2 编写更少的代码 ............................................................................................................4
1.3.3 老调重弹的过早优化 ....................................................................................................5
1.3.4 其他:数据库很可能就是瓶颈 ....................................................................................6
1.3.5 常见的优化 ....................................................................................................................7
1.4 小结 .............................................................................................................................................8
第 2 章 性能测试方法 .......................................................................................................................9
2.1 原则 1:测试真实应用 ..............................................................................................................9
2.1.1 微基准测试 ....................................................................................................................9
2.1.2 宏基准测试 ..................................................................................................................13
2.1.3 介基准测试 ..................................................................................................................15
2.1.4 代码示例 ......................................................................................................................16
2.2 原则 2:理解批处理流逝时间、吞吐量和响应时间 ............................................................19
2.2.1 批处理流逝时间 ..........................................................................................................19
2.2.2 吞吐量测试 ..................................................................................................................20
2.2.3 响应时间测试 ..............................................................................................................20
2.3 原则 3:用统计方法应对性能的变化 ....................................................................................23
2.4 原则 4:尽早频繁测试 ............................................................................................................26
vi | 目录
2.5 小结 ...........................................................................................................................................28
第 3 章 Java 性能调优工具箱 ......................................................................................................29
3.1 操作系统的工具和分析 ...........................................................................................................29
3.1.1 CPU 使用率 ..................................................................................................................29
3.1.2 CPU 运行队列 ..............................................................................................................32
3.1.3 磁盘使用率 ..................................................................................................................33
3.1.4 网络使用率 ..................................................................................................................34
3.2 Java 监控工具 ...........................................................................................................................35
3.2.1 基本的 VM 信息 ..........................................................................................................36
3.2.2 线程信息 ......................................................................................................................39
3.2.3 类信息 ..........................................................................................................................39
3.2.4 实时 GC 分析 ...............................................................................................................39
3.2.5 事后堆转储 ..................................................................................................................39
3.3 性能分析工具 ...........................................................................................................................39
3.3.1 采样分析器 ..................................................................................................................40
3.3.2 探查分析器 ..................................................................................................................41
3.3.3 阻塞方法和线程时间线 ..............................................................................................42
3.3.4 本地分析器 ..................................................................................................................44
3.4 Java 任务控制 ...........................................................................................................................45
3.4.1 Java 飞行记录器 ..........................................................................................................46
3.4.2 开启 JFR .......................................................................................................................52
3.4.3 选择 JFR 事件 ..............................................................................................................54
3.5 小结 ...........................................................................................................................................56
第 4 章 JIT 编译器 ...........................................................................................................................58
4.1 JIT 编译器:概览.....................................................................................................................58
4.2 调优入门:选择编译器类型(Client、Server 或二者同用) ................................................61
4.2.1 优化启动 ......................................................................................................................62
4.2.2 优化批处理 ..................................................................................................................63
4.2.3 优化长时间运行的应用 ..............................................................................................64
4.3 Java 和 JIT 编译器版本 ...........................................................................................................64
4.4 编译器中级调优 .......................................................................................................................67
4.4.1 调优代码缓存 ..............................................................................................................67
4.4.2 编译阈值 ......................................................................................................................68
4.4.3 检测编译过程 ..............................................................................................................70
4.5 高级编译器调优 .......................................................................................................................73
4.5.1 编译线程 ......................................................................................................................73
4.5.2 内联 ..............................................................................................................................74
目录 | vii
4.5.3 逃逸分析 ......................................................................................................................75
4.6 逆优化 .......................................................................................................................................76
4.6.1 代码被丢弃 ..................................................................................................................77
4.6.2 逆优化僵尸代码 ..........................................................................................................78
4.7 分层编译级别 ...........................................................................................................................79
4.8 小结 ...........................................................................................................................................80
第 5 章 垃圾收集入门 .....................................................................................................................81
5.1 垃圾收集概述 ...........................................................................................................................81
5.1.1 分代垃圾收集器 ..........................................................................................................83
5.1.2 GC 算法 ........................................................................................................................84
5.1.3 选择 GC 算法 ...............................................................................................................87
5.2 GC 调优基础 ............................................................................................................................92
5.2.1 调整堆的大小 ..............................................................................................................92
5.2.2 代空间的调整 ..............................................................................................................95
5.2.3 永久代和元空间的调整 ..............................................................................................96
5.2.4 控制并发 ......................................................................................................................97
5.2.5 自适应调整 ..................................................................................................................98
5.3 垃圾回收工具 ...........................................................................................................................99
5.4 小结 .........................................................................................................................................102
第 6 章 垃圾收集算法 ...................................................................................................................103
6.1 理解 Throughput 收集器 ........................................................................................................103
6.2 理解 CMS 收集器 ..................................................................................................................109
6.2.1 针对并发模式失效的调优 ........................................................................................113
6.2.2 CMS 收集器的永久代调优 .......................................................................................116
6.2.3 增量式 CMS 垃圾收集 ..............................................................................................117
6.3 理解 G1 垃圾收集器 ..............................................................................................................118
6.4 高级调优 .................................................................................................................................126
6.4.1 晋升及 Survivor 空间 ................................................................................................126
6.4.2 分配大对象 ................................................................................................................129
6.4.3 AggressiveHeap 标志 ................................................................................................136
6.4.4 全盘掌控堆空间的大小 ............................................................................................137
6.5 小结 .........................................................................................................................................138
第 7 章 堆内存最佳实践 ..............................................................................................................140
7.1 堆分析 .....................................................................................................................................140
7.1.1 堆直方图 ....................................................................................................................141
7.1.2 堆转储 ........................................................................................................................142
7.1.3 内存溢出错误 ............................................................................................................146
viii | 目录
7.2 减少内存使用 .........................................................................................................................149
7.2.1 减少对象大小 ............................................................................................................149
7.2.2 延迟初始化 ................................................................................................................152
7.2.3 不可变对象和标准化对象 ........................................................................................156
7.2.4 字符串的保留 ............................................................................................................157
7.3 对象生命周期管理 .................................................................................................................160
7.3.1 对象重用 ....................................................................................................................160
7.3.2 弱引用、软引用与其他引用 ....................................................................................165
7.4 小结 .........................................................................................................................................175
第 8 章 原生内存最佳实践 ..........................................................................................................176
8.1 内存占用 .................................................................................................................................176
8.1.1 测量内存占用 ............................................................................................................177
8.1.2 内存占用最小化 ........................................................................................................178
8.1.3 原生 NIO 缓冲区 .......................................................................................................178
8.1.4 原生内存跟踪 ............................................................................................................179
8.2 针对不同操作系统优化 JVM ................................................................................................182
8.2.1 大页 ............................................................................................................................182
8.2.2 压缩的 oop .................................................................................................................185
8.3 小结 .........................................................................................................................................187
第 9 章 线程与同步的性能 ..........................................................................................................188
9.1 线程池与 ThreadPoolExecutor .............................................................................................188
9.1.1 设置最大线程数 ........................................................................................................189
9.1.2 设置最小线程数 ........................................................................................................192
9.1.3 线程池任务大小 ........................................................................................................193
9.1.4 设置 ThreadPoolExecutor 的大小 ............................................................................193
9.2 ForkJoinPool ..........................................................................................................................195
9.3 线程同步 .................................................................................................................................201
9.3.1 同步的代价 ................................................................................................................202
9.3.2 避免同步 ....................................................................................................................205
9.3.3 伪共享 ........................................................................................................................208
9.4 JVM 线程调优 ........................................................................................................................211
9.4.1 调节线程栈大小 ........................................................................................................211
9.4.2 偏向锁 ........................................................................................................................212
9.4.3 自旋锁 ........................................................................................................................212
9.4.4 线程优先级 ................................................................................................................213
9.5 监控线程与锁 .........................................................................................................................213
9.5.1 查看线程 ....................................................................................................................214
目录 | ix
9.5.2 查看阻塞线程 ............................................................................................................214
9.6 小结 .........................................................................................................................................217
第 10 章 Java EE 性能调优 ........................................................................................................218
10.1 Web 容器的基本性能 ..........................................................................................................218
10.2 线程池 ...................................................................................................................................222
10.3 EJB 会话 Bean ......................................................................................................................223
10.3.1 调优 EJB 对象池 ....................................................................................................223
10.3.2 调优 EJB 缓存 ........................................................................................................225
10.3.3 本地和远程实例 .....................................................................................................226
10.4 XML 和 JSON 处理 .............................................................................................................227
10.4.1 数据大小 .................................................................................................................227
10.4.2 解析和编组概述 .....................................................................................................229
10.4.3 选择解析器 .............................................................................................................230
10.4.4 XML 验证 ...............................................................................................................235
10.4.5 文档模型 .................................................................................................................237
10.4.6 Java 对象模型 .........................................................................................................240
10.5 对象序列化 ...........................................................................................................................241
10.5.1 transient 字段 .......................................................................................................241
10.5.2 覆盖默认的序列化 .................................................................................................241
10.5.3 压缩序列化数据 .....................................................................................................244
10.5.4 追踪对象复制 .........................................................................................................246
10.6 Java EE 网络 API .................................................................................................................248
10.7 小结 .......................................................................................................................................250
第 11 章 数据库性能的最佳实践 ...............................................................................................251
11.1 JDBC .....................................................................................................................................251
11.1.1 JDBC 驱动程序 ......................................................................................................252
11.1.2 预处理语句和语句池 .............................................................................................253
11.1.3 JDBC 连接池 ..........................................................................................................255
11.1.4 事务 .........................................................................................................................256
11.1.5 结果集的处理 .........................................................................................................262
11.2 JPA ........................................................................................................................................264
11.2.1 事务处理 .................................................................................................................264
11.2.2 对 JPA 的写性能进行优化 .....................................................................................267
11.2.3 对 JPA 的读性能进行优化 .....................................................................................268
11.2.4 JPA 缓存 ..................................................................................................................271
11.2.5 JPA 的只读实体 ......................................................................................................276
11.3 小结 .......................................................................................................................................277
x | 目录
第 12 章 Java SE API 技巧 ........................................................................................................278
12.1 缓冲式 I/O.............................................................................................................................278
12.2 类加载 ...................................................................................................................................280
12.3 随机数 ...................................................................................................................................284
12.4 Java 原生接口 .......................................................................................................................285
12.5 异常 .......................................................................................................................................287
12.6 字符串的性能 .......................................................................................................................290
12.7 日志 .......................................................................................................................................291
12.8 Java 集合类 API ...................................................................................................................292
12.8.1 同步还是非同步 .....................................................................................................293
12.8.2 设定集合的大小 .....................................................................................................294
12.8.3 集合与内存使用效率 .............................................................................................295
12.9 AggressiveOpts 标志 ...........................................................................................................296
12.9.1 替代实现 .................................................................................................................296
12.9.2 其他标志 .................................................................................................................297
12.10 Lambda 表达式和匿名类 ...................................................................................................297
12.11 流和过滤器的性能 .............................................................................................................300
12.12 小结 .....................................................................................................................................302
附录 A 性能调优标志摘要 ...........................................................................................................303
作者简介 ..............................................................................................................................................312
关于封面 ..............................................................................................................................................312

实例下载地址

Java性能权威指南.pdf

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
;
报警