【例子介绍】Java Threads, Third Edition
【相关图片】
【源码结构】
Table Of Contents
1. Java Threads, Third Edition .............................................................................................................. 5
2. Table of Contents ............................................................................................................................. 5
3. Copyright ......................................................................................................................................... 8
4. Preface ............................................................................................................................................. 9
4.1 Who Should Read This Book? .............................................................................................. 10
4.2 Versions Used in This Book .................................................................................................. 10
4.3 What's New in This Edition? ................................................................................................ 11
4.4 Organization of This Book .................................................................................................... 13
4.5 Conventions Used in This Book ............................................................................................ 15
4.6 Code Examples ..................................................................................................................... 16
4.7 How to Contact Us ............................................................................................................... 16
4.8 Safari Enabled ...................................................................................................................... 17
4.9 Acknowledgments ............................................................................................................... 17
5. Chapter 1. Introduction to Threads ............................................................................................... 18
5.1 1.1 Java Terms ...................................................................................................................... 18
5.2 1.2 About the Examples ....................................................................................................... 21
5.3 1.3 Why Threads? ................................................................................................................ 24
5.4 1.4 Summary ........................................................................................................................ 28
6. Chapter 2. Thread Creation and Management .............................................................................. 29
6.1 2.1 What Is a Thread? .......................................................................................................... 29
6.2 2.2 Creating a Thread ........................................................................................................... 33
6.3 2.3 The Lifecycle of a Thread ............................................................................................... 48
6.4 2.4 Two Approaches to Stopping a Thread .......................................................................... 53
6.5 2.5 The Runnable Interface .................................................................................................. 58
6.6 2.6 Threads and Objects ...................................................................................................... 65
6.7 2.7 Summary ........................................................................................................................ 67
7. Chapter 3. Data Synchronization ................................................................................................... 69
7.1 3.1 The Synchronized Keyword ............................................................................................ 69
7.2 3.2 The Volatile Keyword ..................................................................................................... 73
7.3 3.3 More on Race Conditions .............................................................................................. 76
7.4 3.4 Explicit Locking ............................................................................................................... 84
7.5 3.5 Lock Scope ..................................................................................................................... 89
7.6 3.6 Choosing a Locking Mechanism ..................................................................................... 94
7.7 3.7 Nested Locks .................................................................................................................. 96
7.8 3.8 Deadlock ...................................................................................................................... 100
7.9 3.9 Lock Fairness ................................................................................................................ 109
7.10 3.10 Summary .................................................................................................................. 111
8. Chapter 4. Thread Notification .................................................................................................... 112
8.1 4.1 Wait and Notify ............................................................................................................ 113
8.2 4.2 Condition Variables ...................................................................................................... 123
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
2
8.3 4.3 Summary ...................................................................................................................... 128
9. Chapter 5. Minimal Synchronization Techniques......................................................................... 129
9.1 5.1 Can You Avoid Synchronization? .................................................................................. 130
9.2 5.2 Atomic Variables .......................................................................................................... 136
9.3 5.3 Thread Local Variables ................................................................................................. 168
9.4 5.4 Summary ...................................................................................................................... 171
10. Chapter 6. Advanced Synchronization Topics ............................................................................ 172
10.1 6.1 Synchronization Terms ............................................................................................... 173
10.2 6.2 Synchronization Classes Added in J2SE 5.0 ................................................................ 174
10.3 6.3 Preventing Deadlock .................................................................................................. 182
10.4 6.4 Deadlock Detection ................................................................................................... 190
10.5 6.5 Lock Starvation .......................................................................................................... 211
10.6 6.6 Summary .................................................................................................................... 216
11. Chapter 7. Threads and Swing ................................................................................................... 217
11.1 7.1 Swing Threading Restrictions ..................................................................................... 217
11.2 7.2 Processing on the Event-Dispatching Thread ............................................................ 218
11.3 7.3 Using invokeLater( ) and invokeAndWait( ) ................................................................ 219
11.4 7.4 Long-Running Event Callbacks ................................................................................... 222
11.5 7.5 Summary .................................................................................................................... 227
12. Chapter 8. Threads and Collection Classes ................................................................................ 228
12.1 8.1 Overview of Collection Classes .................................................................................. 229
12.2 8.2 Synchronization and Collection Classes ..................................................................... 234
12.3 8.3 The Producer/Consumer Pattern ............................................................................... 245
12.4 8.4 Using the Collection Classes ...................................................................................... 249
12.5 8.5 Summary .................................................................................................................... 250
13. Chapter 9. Thread Scheduling .................................................................................................... 251
13.1 9.1 An Overview of Thread Scheduling ............................................................................ 252
13.2 9.2 Scheduling with Thread Priorities .............................................................................. 262
13.3 9.3 Popular Threading Implementations ......................................................................... 264
13.4 9.4 Summary .................................................................................................................... 272
14. Chapter 10. Thread Pools .......................................................................................................... 273
14.1 10.1 Why Thread Pools? .................................................................................................. 273
14.2 10.2 Executors ................................................................................................................. 277
14.3 10.3 Using a Thread Pool ................................................................................................. 279
14.4 10.4 Queues and Sizes ..................................................................................................... 282
14.5 10.5 Thread Creation ....................................................................................................... 287
14.6 10.6 Callable Tasks and Future Results ............................................................................ 288
14.7 10.7 Single-Threaded Access ........................................................................................... 291
14.8 10.8 Summary .................................................................................................................. 293
15. Chapter 11. Task Scheduling ...................................................................................................... 294
15.1 11.1 Overview of Task Scheduling ................................................................................... 295
15.2 11.2 The java.util.Timer Class .......................................................................................... 296
15.3 11.3 The javax.swing.Timer Class ..................................................................................... 307
15.4 11.4 The ScheduledThreadPoolExecutor Class ................................................................ 312
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
3
15.5 11.5 Summary .................................................................................................................. 322
16. Chapter 12. Threads and I/O ..................................................................................................... 324
16.1 12.1 A Traditional I/O Server ........................................................................................... 325
16.2 12.2 A New I/O Server ..................................................................................................... 343
16.3 12.3 Interrupted I/O ........................................................................................................ 360
16.4 12.4 Summary .................................................................................................................. 365
17. Chapter 13. Miscellaneous Thread Topics ................................................................................. 367
17.1 13.1 Thread Groups ......................................................................................................... 367
17.2 13.2 Threads and Java Security ........................................................................................ 369
17.3 13.3 Daemon Threads ...................................................................................................... 372
17.4 13.4 Threads and Class Loading ....................................................................................... 373
17.5 13.5 Threads and Exception Handling ............................................................................. 374
17.6 13.6 Threads, Stacks, and Memory Usage ....................................................................... 379
17.7 13.7 Summary .................................................................................................................. 384
18. Chapter 14. Thread Performance .............................................................................................. 384
18.1 14.1 Overview of Performance ........................................................................................ 385
18.2 14.2 Synchronized Collections ......................................................................................... 387
18.3 14.3 Atomic Variables and Contended Synchronization .................................................. 389
18.4 14.4 Thread Creation and Thread Pools .......................................................................... 391
18.5 14.5 Summary .................................................................................................................. 392
19. Chapter 15. Parallelizing Loops for Multiprocessor Machines .................................................. 393
19.1 15.1 Parallelizing a Single-Threaded Program ................................................................. 394
19.2 15.2 Multiprocessor Scaling ............................................................................................. 437
19.3 15.3 Summary .................................................................................................................. 456
20. Appendix A. Superseded Threading Utilities ............................................................................. 458
20.1 A.1 The BusyFlag Class ..................................................................................................... 459
20.2 A.2 The CondVar Class ..................................................................................................... 461
20.3 A.3 The Barrier Class ........................................................................................................ 467
20.4 A.4 The RWLock Class ...................................................................................................... 469
20.5 A.5 The ThreadPool Class................................................................................................. 475
20.6 A.6 The JobScheduler Class ............................................................................................. 482
20.7 A.7 Summary ................................................................................................................... 492
21. Colophon ................................................................................................................................... 493
22. Index .......................................................................................................................................... 494
22.1 index_A ............................................................................................................................ 494
22.2 index_B ............................................................................................................................ 495
22.3 index_C ............................................................................................................................ 496
22.4 index_D ............................................................................................................................ 498
22.5 index_E ............................................................................................................................ 498
22.6 index_F ............................................................................................................................ 499
22.7 index_G ............................................................................................................................ 500
22.8 index_H ............................................................................................................................ 500
22.9 index_I ............................................................................................................................. 501
22.10 index_J ........................................................................................................................... 502
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
4
22.11 index_K .......................................................................................................................... 503
22.12 index_L ........................................................................................................................... 503
22.13 index_M ......................................................................................................................... 505
22.14 index_N .......................................................................................................................... 509
22.15 index_O .......................................................................................................................... 509
22.16 index_P .......................................................................................................................... 510
22.17 index_Q .......................................................................................................................... 511
22.18 index_R .......................................................................................................................... 511
22.19 index_S .......................................................................................................................... 512
22.20 index_T .......................................................................................................................... 515
22.21 index_U .......................................................................................................................... 517
22.22 index_V .......................................................................................................................... 518
22.23 index_W ......................................................................................................................... 519
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
5
1. Java Threads, Third Edition
• Table of Contents(See 2.)
• Index(See 22.)
• Reviews
• Reader Reviews
• Errata
• Academic
Java Threads, Third Edition
By Scott Oaks , Henry Wong
Publisher : O'Reilly
Pub Date : September 2004
ISBN : 0-596-00782-5
Pages : 360
Threads are essential to Java programming, but learning to use them effectively is a
nontrivial task. This new edition of the classic Java Threads shows you how to take full
advantage of Java's threading facilities and brings you up-to-date with the watershed
changes in Java 2 Standard Edition version 5.0 (J2SE 5.0). It provides a thorough,
step-by-step approach to threads programming.
2. Table of Contents
• Index(See 22.)
• Reviews
• Reader Reviews
• Errata
• Academic
Java Threads, Third Edition
By Scott Oaks , Henry Wong
Publisher : O'Reilly
Pub Date : September 2004
ISBN : 0-596-00782-5
Pages : 360
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
6
Copyright(See 3.)
Preface(See 4.)
Who Should Read This Book?(See 4.1)
Versions Used in This Book(See 4.2)
What's New in This Edition?(See 4.3)
Organization of This Book(See 4.4)
Conventions Used in This Book(See 4.5)
Code Examples(See 4.6)
How to Contact Us(See 4.7)
Safari Enabled(See 4.8)
Acknowledgments(See 4.9)
Chapter 1. Introduction to Threads(See 5.)
Section 1.1. Java Terms(See 5.1)
Section 1.2. About the Examples(See 5.2)
Section 1.3. Why Threads?(See 5.3)
Section 1.4. Summary(See 5.4)
Chapter 2. Thread Creation and Management(See 6.)
Section 2.1. What Is a Thread?(See 6.1)
Section 2.2. Creating a Thread(See 6.2)
Section 2.3. The Lifecycle of a Thread(See 6.3)
Section 2.4. Two Approaches to Stopping a Thread(See 6.4)
Section 2.5. The Runnable Interface(See 6.5)
Section 2.6. Threads and Objects(See 6.6)
Section 2.7. Summary(See 6.7)
Chapter 3. Data Synchronization(See 7.)
Section 3.1. The Synchronized Keyword(See 7.1)
Section 3.2. The Volatile Keyword(See 7.2)
Section 3.3. More on Race Conditions(See 7.3)
Section 3.4. Explicit Locking(See 7.4)
Section 3.5. Lock Scope(See 7.5)
Section 3.6. Choosing a Locking Mechanism(See 7.6)
Section 3.7. Nested Locks(See 7.7)
Section 3.8. Deadlock(See 7.8)
Section 3.9. Lock Fairness(See 7.9)
Section 3.10. Summary(See 7.10)
Chapter 4. Thread Notification(See 8.)
Section 4.1. Wait and Notify(See 8.1)
Section 4.2. Condition Variables(See 8.2)
Section 4.3. Summary(See 8.3)
Chapter 5. Minimal Synchronization Techniques(See 9.)
Section 5.1. Can You Avoid Synchronization?(See 9.1)
Section 5.2. Atomic Variables(See 9.2)
Section 5.3. Thread Local Variables(See 9.3)
Section 5.4. Summary(See 9.4)
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
7
Chapter 6. Advanced Synchronization Topics(See 10.)
Section 6.1. Synchronization Terms(See 10.1)
Section 6.2. Synchronization Classes Added in J2SE 5.0(See 10.2)
Section 6.3. Preventing Deadlock(See 10.3)
Section 6.4. Deadlock Detection(See 10.4)
Section 6.5. Lock Starvation(See 10.5)
Section 6.6. Summary(See 10.6)
Chapter 7. Threads and Swing(See 11.)
Section 7.1. Swing Threading Restrictions(See 11.1)
Section 7.2. Processing on the Event-Dispatching Thread(See 11.2)
Section 7.3. Using invokeLater( ) and invokeAndWait( )(See 11.3)
Section 7.4. Long-Running Event Callbacks(See 11.4)
Section 7.5. Summary(See 11.5)
Chapter 8. Threads and Collection Classes(See 12.)
Section 8.1. Overview of Collection Classes(See 12.1)
Section 8.2. Synchronization and Collection Classes(See 12.2)
Section 8.3. The Producer/Consumer Pattern(See 12.3)
Section 8.4. Using the Collection Classes(See 12.4)
Section 8.5. Summary(See 12.5)
Chapter 9. Thread Scheduling(See 13.)
Section 9.1. An Overview of Thread Scheduling(See 13.1)
Section 9.2. Scheduling with Thread Priorities(See 13.2)
Section 9.3. Popular Threading Implementations(See 13.3)
Section 9.4. Summary(See 13.4)
Chapter 10. Thread Pools(See 14.)
Section 10.1. Why Thread Pools?(See 14.1)
Section 10.2. Executors(See 14.2)
Section 10.3. Using a Thread Pool(See 14.3)
Section 10.4. Queues and Sizes(See 14.4)
Section 10.5. Thread Creation(See 14.5)
Section 10.6. Callable Tasks and Future Results(See 14.6)
Section 10.7. Single-Threaded Access(See 14.7)
Section 10.8. Summary(See 14.8)
Chapter 11. Task Scheduling(See 15.)
Section 11.1. Overview of Task Scheduling(See 15.1)
Section 11.2. The java.util.Timer Class(See 15.2)
Section 11.3. The javax.swing.Timer Class(See 15.3)
Section 11.4. The ScheduledThreadPoolExecutor Class(See 15.4)
Section 11.5. Summary(See 15.5)
Chapter 12. Threads and I/O(See 16.)
Section 12.1. A Traditional I/O Server(See 16.1)
Section 12.2. A New I/O Server(See 16.2)
Section 12.3. Interrupted I/O(See 16.3)
Section 12.4. Summary(See 16.4)
更多IT编程类电子书尽在:https://shop109847659.taobao.com/或者加微信w33311w免费领取
Java Threads, Third Edition
8
Chapter 13. Miscellaneous Thread Topics(See 17.)
Section 13.1. Thread Groups(See 17.1)
Section 13.2. Threads and Java Security(See 17.2)
Section 13.3. Daemon Threads(See 17.3)
Section 13.4. Threads and Class Loading(See 17.4)
Section 13.5. Threads and Exception Handling(See 17.5)
Section 13.6. Threads, Stacks, and Memory Usage(See 17.6)
Section 13.7. Summary(See 17.7)
Chapter 14. Thread Performance(See 18.)
Section 14.1. Overview of Performance(See 18.1)
Section 14.2. Synchronized Collections(See 18.2)
Section 14.3. Atomic Variables and Contended Synchronization(See 18.3)
Section 14.4. Thread Creation and Thread Pools(See 18.4)
Section 14.5. Summary(See 18.5)
Chapter 15. Parallelizing Loops for Multiprocessor Machines(See 19.)
Section 15.1. Parallelizing a Single-Threaded Program(See 19.1)
Section 15.2. Multiprocessor Scaling(See 19.2)
Section 15.3. Summary(See 19.3)
Appendix A. Superseded Threading Utilities(See 20.)
Section A.1. The BusyFlag Class(See 20.1)
Section A.2. The CondVar Class(See 20.2)
Section A.3. The Barrier Class(See 20.3)
Section A.4. The RWLock Class(See 20.4)
Section A.5. The ThreadPool Class(See 20.5)
Section A.6. The JobScheduler Class(See 20.6)
Section A.7. Summary(See 20.7)
Colophon(See 21.)
Index(See 22.
评论