下载安卓APP箭头
箭头给我发消息

客服QQ:3315713922
读书 > 编程语言 >Java > Java并发编程核心方法与框架

Java并发编程核心方法与框架

综合评级:★★★★★

定价:79.00

作者:高洪岩

出版社:机械工业

出版日期:2016/05/01

页数:354

ISBN:9787111535218

书籍介绍

本书主要介绍非常核心并常用的技术点,比如解决高并发环境下的线程间同步问题,可以使用semaphore,countdownlatch,cyclicbarrier以及phaser类来解决,还要掌握线程池threadpoolexecutor的使用,还有线程池结合计划任务scheduledexecutorservice接口的使用,future接口的使用,completionservice异步任务的使用,executorservice工具接口的使用,fork-join分治编程的学习和java技术中使用率比较高的并发集合框架。

相关课程
目录

第1章 semaphore和exchanger的使用 1

1.1 semaphore的使用 2

1.1.1 类semaphore的同步性 2

1.1.2 类semaphore构造方法permits参数作用 4

1.1.3 方法acquire(int permits)参数作用及动态添加permits许可数量 5

1.1.4 方法acquireuninterruptibly()的使用 8

1.1.5 方法availablepermits()和drainpermits() 10

1.1.6 方法getqueuelength()和hasqueuedthreads() 12

1.1.7 公平与非公平信号量的测试 13

1.1.8 方法tryacquire()的使用 15

1.1.9 方法tryacquire(int permits)的使用 17

1.1.10 方法tryacquire(long timeout, timeunit unit)的使用 17

1.1.11 方法tryacquire(int permits, long timeout, timeunit unit)的使用 19

1.1.12 多进路-多处理-多出路实验 20

1.1.13 多进路-单处理-多出路实验 21

1.1.14 使用semaphore创建字符串池 23

1.1.15 使用semaphore实现多生产者/多消费者模式 25

1.2 exchanger的使用 31

1.2.1 方法exchange()阻塞的特性 31

1.2.2 方法exchange()传递数据 32

1.2.3 方法exchange(v x, long timeout, timeunit unit)与超时 34

1.3 本章总结 35

第2章 countdownlatch和cyclicbarrier的使用 36

2.1 countdownlatch的使用 36

2.1.1 初步使用 37

2.1.2 裁判在等全部的运动员到来 38

2.1.3 各就各位准备比赛 39

2.1.4 完整的比赛流程 41

2.1.5 方法await(long timeout, timeunit unit) 44

2.1.6 方法getcount()的使用 46

2.2 cyclicbarrier的使用 46

2.2.1 初步使用 48

2.2.2 验证屏障重置性及getnumberwaiting()方法的使用 51

2.2.3 用cyclicbarrier类实现阶段跑步比赛 52

2.2.4 方法isbroken()的使用 55

2.2.5 方法await(long timeout, timeunit unit)超时出现异常的测试 57

2.2.6 方法getnumberwaiting()和getparties() 60

2.2.7 方法reset() 62

2.3 本章总结 64

第3章 phaser的使用 65

3.1 phaser的使用 66

3.2 类phaser的arriveandawaitadvance()方法测试1 66

3.3 类phaser的arriveandawaitadvance()方法测试2 68

3.4 类phaser的arriveandderegister()方法测试 69

3.5 类phaser的getphase()和onadvance()方法测试 70

3.6 类phaser的getregisteredparties()方法和register()测试 74

3.7 类phaser的bulkregister()方法测试 75

3.8 类phaser的getarrivedparties()和getunarrivedparties()方法测试 75

3.9 类phaser的arrive()方法测试1 77

3.10 类phaser的arrive ()方法测试2 78

3.11 类phaser的awaitadvance(int phase)方法测试 81

3.12 类phaser的awaitadvanceinterruptibly(int)方法测试1 83

3.13 类phaser的awaitadvanceinterruptibly(int)方法测试2 84

3.14 类phaser的awaitadvanceinterruptibly(int)方法测试3 86

3.15 类phaser的awaitadvanceinterruptibly(int,long,timeunit)方法测试4 87

3.16 类phaser的forcetermination()和isterminated()方法测试 89

3.17 控制phaser类的运行时机 92

3.18 本章总结 93

第4章 executor与threadpoolexecutor的使用 94

4.1 executor接口介绍 94

4.2 使用executors工厂类创建线程池 97

4.2.1 使用newcachedthreadpool()方法创建无界线程池 98

4.2.2 验证newcachedthreadpool()创建为thread池 100

4.2.3 使用newcachedthreadpool (threadfactory)定制线程工厂 102

4.2.4 使用newfixedthreadpool(int)方法创建有界线程池 103

4.2.5 使用newfixedthreadpool(int, threadfactory)定制线程工厂 105

4.2.6 使用newsinglethreadexecutor()方法创建单一线程池 106

4.2.7 使用newsinglethreadexecutor(threadfactory)定制线程工厂 107

4.3 threadpoolexecutor的使用 107

4.3.1 构造方法的测试 107

4.3.2 方法shutdown()和shutdownnow()与返回值 119

4.3.3 方法isshutdown() 129

4.3.4 方法isterminating ()和isterminated () 129

4.3.5 方法awaittermination(long timeout,timeunit unit) 131

4.3.6 工厂threadfactory+execute()+uncaughtexceptionhandler处理异常 134

4.3.7 方法set/getrejectedexecutionhandler() 138

4.3.8 方法allowscorethreadtimeout()/(boolean) 140

4.3.9 方法prestartcorethread()和prestartallcorethreads() 142

4.3.10 方法getcompletedtaskcount() 144

4.3.11 常见3种队列结合max值的因果效果 145

4.3.12 线程池threadpoolexecutor的拒绝策略 151

4.3.13 方法afterexecute()和beforeexecute() 157

4.3.14 方法remove(runnable)的使用 159

4.3.15 多个get方法的测试 162

4.3.16 线程池threadpoolexecutor与runnable执行为乱序特性 166

4.4 本章总结 167

第5章 future和callable的使用 168

5.1 future和callable的介绍 168

5.2 方法get()结合executorservice中的submit(callable)的使用 168

5.3 方法get()结合executorservice中的submit(runnable)和isdone()的使用 170

5.4 使用executorservice接口中的方法submit(runnable, t result) 170

5.5 方法cancel(boolean mayinterruptifrunning)和iscancelled()的使用 173

5.6 方法get(long timeout, timeunit unit)的使用 178

5.7 异常的处理 179

5.8 自定义拒绝策略rejectedexecutionhandler接口的使用 181

5.9 方法execute()与submit()的区别 182

5.10 验证future的缺点 186

5.11 本章总结 188

第6章 completionservice的使用 189

6.1 completionservice介绍 189

6.2 使用completionservice解决future的缺点 190

6.3 使用take()方法 193

6.4 使用poll()方法 194

6.5 使用poll(long timeout, timeunit unit)方法 195

6.6 类completionservice与异常 199

6.7 方法future submit(runnable task, v result)的测试 205

6.8 本章总结 207

第7章 接口executorservice的方法使用 208

7.1 在threadpoolexecutor中使用executorservice中的方法 208

7.2 方法invokeany(collection tasks)的使用与interrupt 209

7.3 方法invokeany()与执行慢的任务异常 212

7.4 方法invokeany()与执行快的任务异常 216

7.5 方法invokeany()与全部异常 220

7.6 方法invokeany(collectiontasks, timeout, timeunit)超时的测试 222

7.7 方法invokeall(collection tasks)全正确 226

7.8 方法invokeall(collection tasks)快的正确慢的异常 227

7.9 方法invokeall(collection tasks)快的异常慢的正确 230

7.10 方法invokeall(collection tasks,long timeout,timeunit unit)先慢后快 232

7.11 方法invokeall(collection tasks,long timeout,timeunit unit)先快后慢 234

7.12 方法invokeall(collection tasks,long timeout,timeunit unit)全慢 236

7.13 本章总结 238

第8章 计划任务scheduledexecutorservice的使用 239

8.1 scheduledexecutorservice的使用 240

8.2 scheduledthreadpoolexecutor使用callable延迟运行 241

8.3 scheduledthreadpoolexecutor使用runnable延迟运行 244

8.4 延迟运行并取得返回值 245

8.5 使用scheduleatfixedrate()方法实现周期性执行 246

8.6 使用schedulewithfixeddelay()方法实现周期性执行 248

8.7 使用getqueue()与remove()方法 250

8.8 方法setexecuteexistingdelayedtasksaftershutdownpolicy()的使用 253

8.9 方法setcontinueexistingperiodictasksaftershutdownpolicy() 255

8.10 使用cancel(boolean)与setremoveoncancelpolicy()方法 257

8.11 本章总结 261

第9章 fork-join分治编程 262

9.1 fork-join分治编程与类结构 262

9.2 使用recursiveaction让任务跑起来 264

9.3 使用recursiveaction分解任务 265

9.4 使用recursivetask取得返回值与join()和get()方法的区别 266

9.5 使用recursivetask执行多个任务并打印返回值 270

9.6 使用recursivetask实现字符串累加 272

9.7 使用fork-join实现求和:实验1 273

9.8 使用fork-join实现求和:实验2 275

9.9 类forkjoinpool核心方法的实验 276

9.9.1 方法public void execute(forkjointask task)的使用 276

9.9.2 方法public void execute(runnable task)的使用 278

9.9.3 方法public void execute(forkjointask task)如何处理返回值 278

9.9.4 方法public forkjointask submit(forkjointask task)的使用 279

9.9.5 方法public forkjointask submit(runnable task)的使用 280

9.9.6 方法public forkjointask submit(callable task)的使用 281

9.9.7 方法public forkjointask submit(runnable task, t result)的使用 282

9.9.8 方法public list> invokeall(collection> tasks)的使用 285

9.9.9 方法public void shutdown()的使用 286

9.9.10 方法public list shutdownnow()的使用 289

9.9.11 方法isterminating()和isterminated()的使用 292

9.9.12 方法public boolean isshutdown()的使用 295

9.9.13 方法public boolean awaittermination(long timeout, timeunit unit)的使用 297

9.9.14 方法public t invoke(forkjointask task)的使用 299

9.9.15 监视pool池的状态 301

9.10 类forkjointask对异常的处理 308

9.11 本章总结 309

第10章 并发集合框架 310

10.1 集合框架结构简要 310

10.1.1 接口iterable 310

10.1.2 接口collection 311

10.1.3 接口list 311

10.1.4 接口set 312

10.1.5 接口queue 312

10.1.6 接口deque 312

10.2 非阻塞队列 313

10.2.1 类concurrenthashmap的使用 313

10.2.2 类concurrentskiplistmap的使用 322

10.2.3 类concurrentskiplistset的使用 325

10.2.4 类concurrentlinkedqueue的使用 328

10.2.5 类concurrentlinkeddeque的使用 330

10.2.6 类copyonwritearraylist的使用 332

10.2.7 类copyonwritearrayset的使用 335

10.3 阻塞队列 337

10.3.1 类arrayblockingqueue的使用 337

10.3.2 类priorityblockingqueue的使用 338

10.3.3 类linkedblockingqueue的使用 340

10.3.4 类linkedblockingdeque的使用 341

10.3.5 类synchronousqueue的使用 341

10.3.6 类delayqueue的使用 344

10.3.7 类linkedtransferqueue的使用 345

10.4 本章总结 354

热门图书
推荐新闻
技术文库
论坛推荐