Java Concurrent Programming Combat (Chinese version) pdf

Source: Internet
Author: User
Tags closure visibility volatile

: Network Disk Download

Content Introduction· · · · · ·

This book introduces Java threading and concurrency in a more comprehensible way, and is a perfect Java concurrency reference manual. From the basic concepts of concurrency and thread safety, the book describes how to use the basic concurrency building blocks provided by class libraries to avoid concurrency hazards, construct thread-safe classes and validate thread-safe rules, how to combine small thread-safe classes into larger thread-safe classes, and how to leverage threads to increase throughput for concurrent applications. How to identify tasks that can be executed in parallel, how to improve the responsiveness of single-threaded subsystems, how to ensure that concurrent programs perform the expected tasks, how to improve the performance and scalability of concurrent code, and so on, and finally introduce some advanced topics such as explicit locks, atomic variables, nonblocking algorithms, and how to develop custom synchronization tool classes.

This book is intended for developers of Java programs to read.

Author profile ...

The authors of this book are the main members of the Java Community Process JSR 166 Expert Group (concurrency tool) and are represented in many other JCP expert groups. Brian Goetz has more than 20 years of experience in the software consulting industry and has at least 75 articles on Java development. Tim Peierls is a model of "modern multiprocessor," and he has studied boxpop.biz, record art and theatrical performances. Joseph Bowbeer is a Java me expert, and his interest in concurrent programming began in the era of the Apollo computer. David Holmes, co-author of the book "The Java Programming Language", worked for Sun. Joshua Bloch is the author of Google's chief Java architect, effective Java, and is involved in the book Java puzzlers. Doug Lea is the author of the book Concurrent Programming, a professor of computer science at the State University of New York at Oswego.

Catalogue-Praise for the book
Translator sequence
Objective
Chapter 1th Introduction 1
1.1 History of Concurrency 1
1.2 Advantages of Threading 2
1.2.1 The power of multi-processor 2
1.2.2 Simplicity of Modeling 3
1.2.3 Simplified handling of asynchronous Events 3
1.2.4 responds to a more responsive user interface 4
1.3 Thread-Risk 4
1.3.1 Security Issues 5
1.3.2 Active Question 7
1.3.3 Performance Issues 7
1.4 Threads Everywhere 7
The first part of the basic knowledge
Chapter 2nd Thread Safety 11
2.1 What is thread safety 13
2.2 Atomicity 14
2.2.1 Race Condition 15
2.2.2 Example: Race condition in deferred initialization 16
2.2.3 Compound Operation 17
2.3 Plus lock mechanism 18
2.3.1 Built-in lock 20
2.3.2 Re-entry 21
2.4 Using a lock to protect the state 22
2.5 Activity and Performance 23
Chapter 3rd sharing of Objects 27
3.1 Visibility 27
3.1.1 Failure Data 28
3.1.2 64-bit operation for non-atomic 29
3.1.3 Locking and Visibility 30
3.1.4 Volatile Variable 30
3.2 Release and Escape 32
3.3 Thread Closure 35
3.3.1 Ad-hoc Thread Closure 35
3.3.2 Stack Closure 36
3.3.3 Threadlocal Class 37
3.4 Invariance 38
3.4.1 Final Domain 39
3.4.2 Example: Using volatile types to publish immutable objects 40
3.5 Security Release 41
3.5.1 Incorrect release: The correct object was destroyed 42
3.5.2 immutable objects and initialization security 42
3.5.3 Common patterns for secure publishing 43
3.5.4 Facts Non-volatile object 44
3.5.5 Variable Object 44
3.5.6 Sharing objects Securely 44
Chapter 4th Composition of Objects 46
4.1 Designing Thread-Safe Classes 46
4.1.1 Collecting synchronization Requirements 47
4.1.2 Dependent State Operation 48
Ownership of the 4.1.3 State 48
4.2 Instance Closure 49
4.2.1 Java Monitor Mode 51
4.2.2 Example: Vehicle tracking 51
4.3 Delegate for thread safety 53
4.3.1 Example: Consignment-based vehicle tracker 54
4.3.2 Independent State Variable 55
4.3.3 when a delegate fails 56
4.3.4 Publishing the underlying state variable 57
4.3.5 Example: Release status of Vehicle tracker 58
4.4 Adding features to existing thread-safe classes 59
4.4.1 Client plus lock mechanism 60
4.4.2 Combination 62
4.5 Documenting the synchronization policy 62
5th Basic Building Module 66
5.1 Synchronizing Container Classes 66
5.1.1 problems with the synchronization container class 66
5.1.2 Iterators and concurrent-modificationexception68
5.1.3 Hidden iterators 69
5.2 Concurrent Containers 70
5.2.1 ConcurrentHashMap71
5.2.2 Additional atomic Map Operations 72
5.2.3 CopyOnWriteArrayList72
5.3 Blocking queue and producer-consumer mode 73
5.3.1 Example: Desktop Search 75
5.3.2 Serial Thread Closure 76
5.3.3 Dual-ended queue and work 77
5.4 Blocking method and interrupt method 77
5.5 Sync Tool Class 78
5.5.1 Latching 79
5.5.2 FutureTask80
5.5.3 Signal Volume 82
5.5.4 Fence 83
5.6 Building an efficient and scalable result cache 85
The second part of structured concurrent applications
Chapter 6th Task Execution 93
6.1 Performing tasks in Threads 93
6.1.1 Performing tasks serially 94
6.1.2 Creating threads for tasks explicitly 94
6.1.3 less than 95 of unlimited creation threads
6.2 Executor Frame 96
6.2.1 Example: Executor-based Web server 97
6.2.2 Execution Strategy 98
6.2.3 Thread Pool 98
Life cycle of 6.2.4 Executor 99
6.2.5 delay task and Cycle Task 101
6.3 finding out which parallelism to use 102
6.3.1 Example: Serial page renderer 102
6.3.2 Task callable and Future103 carrying results
6.3.3 Example: Using the future to implement the page renderer 104
Limitations of 6.3.4 in heterogeneous task parallelism 106
6.3.5 Completionservice:executor and BlockingQueue106
6.3.6 Example: Implementing a page renderer with Completionservice 107
6.3.7 set a time limit for a task 108
6.3.8 Example: Travel booking Portal 109
7th. Cancellation and Closure 111
7.1 Task Cancellation 111
7.1.1 Interrupt 113
7.1.2 Interrupt Policy 116
7.1.3 Response Interrupt 117
7.1.4 Example: Timed Run 118
7.1.5 through the future to achieve cancellation 120
7.1.6 handling non-disruptive blocking 121
7.1.7 uses newtaskfor to encapsulate non-standard cancellation 122
7.2 Stopping a thread-based service 124
7.2.1 Example: Log service 124
7.2.2 Close ExecutorService127
7.2.3 "Poison pill" object 128
7.2.4 Example: Service performed only once 129
Limitations of 7.2.5 Shutdownnow 130
7.3 Handling Abnormal Thread termination 132
7.4 JVM off 135
7.4.1 Closing Hooks 135
7.4.2 Daemon Thread 136
7.4.3 Terminator 136
8th use of thread pool 138
8.1 Implicit coupling between task and execution strategy 138
8.1.1 Thread Starvation Deadlock 139
8.1.2 long-running tasks 140
8.2 Setting the size of the thread pool 140
8.3 Configuring ThreadPoolExecutor141
Creation and destruction of 8.3.1 threads 142
8.3.2 Managing Queue Tasks 142
8.3.3 Saturation Strategy 144
8.3.4 Thread Factory 146
8.3.5 Custom ThreadPoolExecutor147 after calling the constructor
8.4 Extension ThreadPoolExecutor148
8.5 parallelization of recursive algorithms 149
9th. Graphical user Interface Application 156
9.1 Why GUI is single thread 156
9.1.1 Serial Event Processing 157
9.1.2 thread closure mechanism in swing 158
9.2 Short-time GUI tasks 160
9.3 Long-time GUI tasks 161
9.3.1 Cancel 162
9.3.2 Progress identification and completion identification 163
9.3.3 SwingWorker165
9.4 Shared Data Model 165
9.4.1 thread-Safe data Model 166
9.4.2 Decomposition Data Model 166
9.5 Other forms of single-threaded subsystems 167
The third part of the activity, performance and testing
10th. Avoidance of active risk 169
10.1 Dead Lock 169
10.1.1 Lock sequence Deadlock 170
10.1.2 Dynamic lock sequence deadlock 171
10.1.3 deadlocks that occur between collaboration objects 174
10.1.4 Open Call 175
10.1.5 Resource Deadlock 177
10.2 Avoidance and diagnosis of deadlocks 178
10.2.1 Support for timed locks 178
10.2.2 parsing deadlocks with thread dump information 178
10.3 Other active sexual dangers 180
10.3.1 Hunger 180
10.3.2 Poor responsiveness 181
10.3.3 Live Lock 181
11th Chapter Performance and Scalability 183
11.1 Thinking about performance 183
11.1.1 Performance and Scalability 184
11.1.2 evaluation of various performance tradeoff factors 185
11.2 Amdahl Law 186
11.2.1 Example: The serial part hidden in various frames 188
Application of 11.2.2 Amdahl Law 189
11.3 Thread-introduced overhead 189
11.3.1 Context Switch 190
11.3.2 Memory Sync 190
11.3.3 Blocking 192
11.4 Reduction of the competition of the lock 192
11.4.1 Narrowing the Lock range ("Fast forward fast-forward") 193
11.4.2 reduce the size of the lock 195
11.4.3 Lock Segment 196
11.4.4 Avoid hotspot domain 197
11.4.5 Some alternative exclusive locks method 198
11.4.6 Monitoring CPU Utilization 199
11.4.7 say "No" to the object pool 200
11.5 Example: Comparing the performance of a map 200
11.6 Reducing the cost of context switching 201
12th test of concurrent Programs 204
12.1 Correctness Test 205
12.1.1 Basic Unit Test 206
12.1.2 test for blocking operations 207
12.1.3 Security Test 208
12.1.4 Resource Management Test 212
12.1.5 using callbacks 213
12.1.6 generates more alternating operations 214
12.2 Performance Test 215
12.2.1 added chronograph function in Puttaketest 215
12.2. Comparison of more than 2 different algorithms 217
12.2.3 Responsiveness Measurement 218
12.3 Pitfalls of avoiding performance tests 220
12.3.1 Garbage Collection 220
12.3.2 Dynamic Compilation 220
12.3.3 false sampling of code paths 222
12.3.4 the level of competition is not true 222
12.3.5 Elimination of useless Code 223
12.4 Other test Methods 224
12.4.1 Code Review 224
12.4.2 Static Analysis Tool 224
12.4.3 aspect-oriented testing technology 226
12.4.4 Analysis and Monitoring tool 226
Part IV Advanced Topics
13th Chapter Explicit Lock 227
13.1 Lock and ReentrantLock227
13.1.1 polling lock and timing lock 228
13.1.2 interruptible Lock Acquisition Operation 230
13.1.3 locking of non-block structure 231
13.2 Performance Considerations 231
13.3 Fair Sex 232
13.4 Choose between synchronized and Reentrantlock 234
13.5 read-Write lock 235
14th. Building a custom Sync tool 238
14.1 Management of State dependencies 238
14.1.1 Example: passing a precondition failure to the caller 240
14.1.2 Example: Implementing simple blocking with polling and hibernation 241
14.1.3 Conditional Queue 243
14.2 Using conditional queue 244
14.2.1 Conditional predicate 244
14.2.2 Premature Wake up 245
14.2.3 Lost Signal 246
14.2.4 Notice 247
14.2.5 Example: Valve class 248
14.2.6 sub-class security issues 249
14.2.7 Package Condition Queue 250
14.2.8 Entry Agreement and export Agreement 250
14.3 Explicit Condition Objects 251
14.4 Synchronizer Anatomy 253
14.5 AbstractQueuedSynchronizer254
14.6 AQS257 in the Java.util.concurrent Synchronizer class
14.6.1 ReentrantLock257
14.6.2 Semaphore and CountDownLatch258
14.6.3 FutureTask259
14.6.4 ReentrantReadWriteLock259
15th Atom variable and non-blocking synchronization mechanism 261
15.1 Disadvantages of the lock 261
15.2 hardware-to-concurrency support 262
15.2.1 Compare and Exchange 263
15.2.2 non-blocking counter 264
15.2.3 JVM support for CAS 265
15.3 Atomic Variable Class 265
15.3.1 Atomic variable is a "better volatile" 266
15.3.2 Performance Comparison: Locks and atomic Variables 267
15.4 non-blocking algorithm 270
15.4.1 non-blocking stack 270
15.4.2 non-blocking linked list 272
Domain Updater for 15.4.3 atoms 274
15.4.4 ABA Question 275
16th Chapter Java Memory Model 277
16.1 What is the memory model and why it needs 277
Memory model of the 16.1.1 platform 278
16.1.2 reordering 278
16.1.3 Java Memory Model Introduction 280
16.1.4 with Sync 281
16.2 Release 283
16.2.1 Unsafe Release 283
16.2.2 Security Release 284
16.2.3 Safe Initialization Mode 284
16.2.4 double check plus lock 286
16.3 Security during initialization 287
Appendix A concurrency Callout 289
References 291

: Network Disk Download

Java Concurrent Programming Combat (Chinese version) pdf

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.